-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from VSCodeVim/fixes
fixes; add VimError class
- Loading branch information
Showing
4 changed files
with
81 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import * as util from "./util"; | ||
|
||
interface VimErrors { | ||
[index: number] : string; | ||
} | ||
|
||
export enum ErrorCode { | ||
E37 = 37, | ||
E32 = 32 | ||
} | ||
|
||
const errors : VimErrors = { | ||
32: "No file name", | ||
37: "No write since last change (add ! to override)" | ||
}; | ||
|
||
|
||
export class VimError extends Error { | ||
|
||
private _code : number; | ||
private _message : string; | ||
|
||
constructor(code : number, message : string) { | ||
super(); | ||
this._code = code; | ||
this._message = message; | ||
} | ||
|
||
static fromCode(code : ErrorCode) : VimError { | ||
if (errors[code]) { | ||
return new VimError(code, errors[code]); | ||
} | ||
|
||
throw new Error("unknown error code: " + code); | ||
} | ||
|
||
get code() : number { | ||
return this._code; | ||
} | ||
|
||
get message() : string { | ||
return this._message; | ||
} | ||
|
||
display() : void { | ||
util.showError(this.toString()); | ||
} | ||
|
||
toString() : string { | ||
return "E" + this.code.toString() + ": " + this.message; | ||
} | ||
} |