Skip to content

Commit e3940b3

Browse files
committed
Slight refactor
1 parent 9de59f5 commit e3940b3

File tree

3 files changed

+99
-99
lines changed

3 files changed

+99
-99
lines changed

src/cmd_line/commands/let.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export class LetCommand extends ExCommand {
227227
'vim_did_enter',
228228
]
229229
) {
230-
throw VimError.fromCode(ErrorCode.CannotChangeReadOnlyVariable);
230+
throw VimError.fromCode(ErrorCode.CannotChangeReadOnlyVariable); // TODO: Include variable name
231231
}
232232
context.setVariable(variable, newValue(variable, value), this.args.lock);
233233
} else if (variable.type === 'register') {

src/error.ts

Lines changed: 97 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
interface IErrorMessage {
2-
[index: number]: string;
3-
}
4-
51
export enum ErrorCode {
62
InvalidAddress = 14,
73
InvalidExpression = 15,
@@ -97,99 +93,103 @@ export enum ErrorCode {
9793
ListRequiredForArgument = 1211,
9894
}
9995

100-
export const ErrorMessage: IErrorMessage = {
101-
14: 'Invalid address',
102-
15: 'Invalid expression',
103-
16: 'Invalid range',
104-
20: 'Mark not set',
105-
23: 'No alternate file',
106-
29: 'No inserted text yet',
107-
32: 'No file name',
108-
33: 'No previous substitute regular expression',
109-
34: 'No previous command',
110-
35: 'No previous regular expression',
111-
37: 'No write since last change (add ! to override)',
112-
46: 'Cannot change read-only variable',
113-
93: 'More than one match',
114-
94: 'No matching buffer',
115-
108: 'No such variable',
116-
114: 'Missing quote',
117-
117: 'Unknown function',
118-
118: 'Too many arguments for function',
119-
119: 'Not enough arguments for function',
120-
121: 'Undefined variable',
121-
208: 'Error writing to file',
122-
211: 'File no longer available', // TODO: Should be `File "[file_name]" no longer available`
123-
223: 'Recursive mapping',
124-
348: 'No string under cursor',
125-
353: 'Nothing in register',
126-
354: 'Invalid register name',
127-
384: 'Search hit TOP without match for',
128-
385: 'Search hit BOTTOM without match for',
129-
444: 'Cannot close last window',
130-
447: 'Can\'t find file "{FILE_NAME}" in path',
131-
471: 'Argument required',
132-
474: 'Invalid argument',
133-
475: 'Invalid argument',
134-
481: 'No range allowed',
135-
486: 'Pattern not found',
136-
488: 'Trailing characters',
137-
492: 'Not an editor command',
138-
516: 'No buffers were deleted',
139-
518: 'Unknown option',
140-
521: 'Number required after =',
141-
662: 'At start of changelist',
142-
663: 'At end of changelist',
143-
664: 'changelist is empty',
144-
684: 'list index out of range',
145-
686: 'Argument of sort() must be a List',
146-
687: 'Less targets than List items',
147-
688: 'More targets than List items',
148-
689: 'Can only index a List, Dictionary or Blob',
149-
691: 'Can only compare List with List',
150-
692: 'Invalid operation for List',
151-
694: 'Invalid operation for Funcrefs',
152-
695: 'Cannot index a Funcref',
153-
700: 'Unknown function',
154-
701: 'Invalid type for len()',
155-
703: 'Using a Funcref as a Number',
156-
704: 'Funcref variable name must start with a capital',
157-
709: '[:] requires a List or Blob value',
158-
710: 'List value has more items than target',
159-
711: 'List value has not enough items',
160-
712: 'Argument of max() must be a List or Dictionary',
161-
714: 'List required',
162-
715: 'Dictionary required',
163-
716: 'Key not present in Dictionary',
164-
719: 'Cannot use [:] with a Dictionary',
165-
721: 'Duplicate key in Dictionary',
166-
726: 'Stride is zero',
167-
727: 'Start past end',
168-
728: 'Using a Dictionary as a Number',
169-
729: 'using Funcref as a String',
170-
730: 'Using List as a String',
171-
731: 'Using Dictionary as a String',
172-
735: 'Can only compare Dictionary with Dictionary',
173-
736: 'Invalid operation for Dictionary',
174-
741: 'Value is locked',
175-
745: 'Using a List as a Number',
176-
748: 'No previously used register',
177-
804: "Cannot use '%' with Float",
178-
805: 'Using a Float as a Number',
179-
806: 'Using Float as a String',
180-
808: 'Number or Float required',
181-
896: 'Argument of map() must be a List, Dictionary or Blob',
182-
897: 'List or Blob required',
183-
900: 'maxdepth must be a non-negative number',
184-
922: 'expected a dict',
185-
923: 'Second argument of function() must be a list or a dict',
186-
973: 'Blob literal should have an even number of hex characters',
187-
974: 'Using a Blob as a Number',
188-
977: 'Can only compare Blob with Blob',
189-
978: 'Invalid operation for Blob',
190-
995: 'Cannot modify existing variable',
191-
996: 'Cannot lock a register',
192-
1211: 'List required for argument {IDX}',
96+
export const ErrorMessage: Record<ErrorCode, string> = {
97+
[ErrorCode.InvalidAddress]: 'Invalid address',
98+
[ErrorCode.InvalidExpression]: 'Invalid expression',
99+
[ErrorCode.InvalidRange]: 'Invalid range',
100+
[ErrorCode.MarkNotSet]: 'Mark not set',
101+
[ErrorCode.NoAlternateFile]: 'No alternate file',
102+
[ErrorCode.NoInsertedTextYet]: 'No inserted text yet',
103+
[ErrorCode.NoFileName]: 'No file name',
104+
[ErrorCode.NoPreviousSubstituteRegularExpression]: 'No previous substitute regular expression',
105+
[ErrorCode.NoPreviousCommand]: 'No previous command',
106+
[ErrorCode.NoPreviousRegularExpression]: 'No previous regular expression',
107+
[ErrorCode.NoWriteSinceLastChange]: 'No write since last change (add ! to override)',
108+
[ErrorCode.CannotChangeReadOnlyVariable]: 'Cannot change read-only variable',
109+
[ErrorCode.MultipleMatches]: 'More than one match',
110+
[ErrorCode.NoMatchingBuffer]: 'No matching buffer',
111+
[ErrorCode.NoSuchVariable]: 'No such variable',
112+
[ErrorCode.MissingQuote]: 'Missing quote',
113+
[ErrorCode.UnknownFunction_call]: 'Unknown function',
114+
[ErrorCode.TooManyArgs]: 'Too many arguments for function',
115+
[ErrorCode.NotEnoughArgs]: 'Not enough arguments for function',
116+
[ErrorCode.UndefinedVariable]: 'Undefined variable',
117+
[ErrorCode.ErrorWritingToFile]: 'Error writing to file',
118+
[ErrorCode.FileNoLongerAvailable]: 'File no longer available', // TODO: Should be `File "[file_name]" no longer available`
119+
[ErrorCode.RecursiveMapping]: 'Recursive mapping',
120+
[ErrorCode.NoStringUnderCursor]: 'No string under cursor',
121+
[ErrorCode.NothingInRegister]: 'Nothing in register',
122+
[ErrorCode.InvalidRegisterName]: 'Invalid register name',
123+
[ErrorCode.SearchHitTop]: 'Search hit TOP without match for',
124+
[ErrorCode.SearchHitBottom]: 'Search hit BOTTOM without match for',
125+
[ErrorCode.CannotCloseLastWindow]: 'Cannot close last window',
126+
[ErrorCode.CantFindFileInPath]: 'Can\'t find file "{FILE_NAME}" in path',
127+
[ErrorCode.ArgumentRequired]: 'Argument required',
128+
[ErrorCode.InvalidArgument474]: 'Invalid argument',
129+
[ErrorCode.InvalidArgument475]: 'Invalid argument',
130+
[ErrorCode.NoRangeAllowed]: 'No range allowed',
131+
[ErrorCode.PatternNotFound]: 'Pattern not found',
132+
[ErrorCode.TrailingCharacters]: 'Trailing characters',
133+
[ErrorCode.NotAnEditorCommand]: 'Not an editor command',
134+
[ErrorCode.NoBuffersDeleted]: 'No buffers were deleted',
135+
[ErrorCode.UnknownOption]: 'Unknown option',
136+
[ErrorCode.NumberRequiredAfterEqual]: 'Number required after =',
137+
[ErrorCode.AtStartOfChangeList]: 'At start of changelist',
138+
[ErrorCode.AtEndOfChangeList]: 'At end of changelist',
139+
[ErrorCode.ChangeListIsEmpty]: 'changelist is empty',
140+
[ErrorCode.ListIndexOutOfRange]: 'list index out of range',
141+
[ErrorCode.ArgumentOfSortMustBeAList]: 'Argument of sort() must be a List',
142+
[ErrorCode.LessTargetsThanListItems]: 'Less targets than List items',
143+
[ErrorCode.MoreTargetsThanListItems]: 'More targets than List items',
144+
[ErrorCode.CanOnlyIndexAListDictionaryOrBlob]: 'Can only index a List, Dictionary or Blob',
145+
[ErrorCode.CanOnlyCompareListWithList]: 'Can only compare List with List',
146+
[ErrorCode.InvalidOperationForList]: 'Invalid operation for List',
147+
[ErrorCode.InvalidOperationForFuncrefs]: 'Invalid operation for Funcrefs',
148+
[ErrorCode.CannotIndexAFuncref]: 'Cannot index a Funcref',
149+
[ErrorCode.UnknownFunction_funcref]: 'Unknown function',
150+
[ErrorCode.InvalidTypeForLen]: 'Invalid type for len()',
151+
[ErrorCode.UsingAFuncrefAsANumber]: 'Using a Funcref as a Number',
152+
[ErrorCode.FuncrefVariableNameMustStartWithACapital]:
153+
'Funcref variable name must start with a capital',
154+
[ErrorCode.SliceRequiresAListOrBlobValue]: '[:] requires a List or Blob value',
155+
[ErrorCode.ListValueHasMoreItemsThanTarget]: 'List value has more items than target',
156+
[ErrorCode.ListValueHasNotEnoughItems]: 'List value has not enough items',
157+
[ErrorCode.ArgumentOfMaxMustBeAListOrDictionary]:
158+
'Argument of max() must be a List or Dictionary',
159+
[ErrorCode.ListRequired]: 'List required',
160+
[ErrorCode.DictionaryRequired]: 'Dictionary required',
161+
[ErrorCode.KeyNotPresentInDictionary]: 'Key not present in Dictionary',
162+
[ErrorCode.CannotUseSliceWithADictionary]: 'Cannot use [:] with a Dictionary',
163+
[ErrorCode.DuplicateKeyInDictionary]: 'Duplicate key in Dictionary',
164+
[ErrorCode.StrideIsZero]: 'Stride is zero',
165+
[ErrorCode.StartPastEnd]: 'Start past end',
166+
[ErrorCode.UsingADictionaryAsANumber]: 'Using a Dictionary as a Number',
167+
[ErrorCode.UsingFuncrefAsAString]: 'using Funcref as a String',
168+
[ErrorCode.UsingListAsAString]: 'Using List as a String',
169+
[ErrorCode.UsingDictionaryAsAString]: 'Using Dictionary as a String',
170+
[ErrorCode.CanOnlyCompareDictionaryWithDictionary]: 'Can only compare Dictionary with Dictionary',
171+
[ErrorCode.InvalidOperationForDictionary]: 'Invalid operation for Dictionary',
172+
[ErrorCode.ValueIsLocked]: 'Value is locked',
173+
[ErrorCode.UsingAListAsANumber]: 'Using a List as a Number',
174+
[ErrorCode.NoPreviouslyUsedRegister]: 'No previously used register',
175+
[ErrorCode.CannotUseModuloWithFloat]: "Cannot use '%' with Float",
176+
[ErrorCode.UsingAFloatAsANumber]: 'Using a Float as a Number',
177+
[ErrorCode.UsingFloatAsAString]: 'Using Float as a String',
178+
[ErrorCode.NumberOrFloatRequired]: 'Number or Float required',
179+
[ErrorCode.ArgumentOfMapMustBeAListDictionaryOrBlob]:
180+
'Argument of map() must be a List, Dictionary or Blob',
181+
[ErrorCode.ListOrBlobRequired]: 'List or Blob required',
182+
[ErrorCode.MaxDepthMustBeANonNegativeNumber]: 'maxdepth must be a non-negative number',
183+
[ErrorCode.ExpectedADict]: 'expected a dict',
184+
[ErrorCode.SecondArgumentOfFunction]: 'Second argument of function() must be a list or a dict',
185+
[ErrorCode.BlobLiteralShouldHaveAnEvenNumberOfHexCharacters]:
186+
'Blob literal should have an even number of hex characters',
187+
[ErrorCode.UsingABlobAsANumber]: 'Using a Blob as a Number',
188+
[ErrorCode.CanOnlyCompareBlobWithBlob]: 'Can only compare Blob with Blob',
189+
[ErrorCode.InvalidOperationForBlob]: 'Invalid operation for Blob',
190+
[ErrorCode.CannotModifyExistingVariable]: 'Cannot modify existing variable',
191+
[ErrorCode.CannotLockARegister]: 'Cannot lock a register',
192+
[ErrorCode.ListRequiredForArgument]: 'List required for argument {IDX}',
193193
};
194194

195195
export class VimError extends Error {

test/error.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ suite('Error', () => {
66
test('error code has message', () => {
77
// eslint-disable-next-line guard-for-in
88
for (const errorCodeString in ErrorCode) {
9-
const errorCode = Number(errorCodeString);
9+
const errorCode = Number(errorCodeString) as ErrorCode;
1010
if (!isNaN(errorCode)) {
1111
assert.notStrictEqual(ErrorMessage[errorCode], undefined, errorCodeString);
1212
}

0 commit comments

Comments
 (0)