diff --git a/src/vs/base/common/errors.ts b/src/vs/base/common/errors.ts index 0bdcb986ad6..24ac4ae2794 100644 --- a/src/vs/base/common/errors.ts +++ b/src/vs/base/common/errors.ts @@ -380,8 +380,10 @@ export function illegalState(name?: string): Error { } } -export function readonly(): Error { - return new Error('readonly property cannot be changed'); +export function readonly(name?: string): Error { + return name + ? new Error(`readonly property '${name} cannot be changed'`) + : new Error('readonly property cannot be changed'); } export function loaderError(err: Error): Error { diff --git a/src/vs/workbench/api/node/extHostEditors.ts b/src/vs/workbench/api/node/extHostEditors.ts index a20d98d4bb6..9e33cd99f3f 100644 --- a/src/vs/workbench/api/node/extHostEditors.ts +++ b/src/vs/workbench/api/node/extHostEditors.ts @@ -5,6 +5,7 @@ 'use strict'; import URI from 'vs/base/common/uri'; +import {readonly, illegalArgument} from 'vs/base/common/errors'; import {IdGenerator} from 'vs/base/common/idGenerator'; import Event, {Emitter} from 'vs/base/common/event'; import {IDisposable, dispose} from 'vs/base/common/lifecycle'; @@ -268,24 +269,13 @@ export class TextEditorEdit { setEndOfLine(endOfLine:EndOfLine): void { if (endOfLine !== EndOfLine.LF && endOfLine !== EndOfLine.CRLF) { - throw illegalArg('endOfLine'); + throw illegalArgument('endOfLine'); } this._setEndOfLine = endOfLine; } } -function readonly(name: string, alt?: string) { - let message = `The property '${name}' is readonly.`; - if (alt) { - message += ` Use '${alt}' instead.`; - } - return new Error(message); -} - -function illegalArg(name: string) { - return new Error(`illgeal argument '${name}'`); -} function deprecated(name: string, message: string = 'Refer to the documentation for further details.') { return (target: Object, key: string, descriptor: TypedPropertyDescriptor) => { @@ -379,7 +369,7 @@ class ExtHostTextEditor implements vscode.TextEditor { set selection(value: Selection) { if (!(value instanceof Selection)) { - throw illegalArg('selection'); + throw illegalArgument('selection'); } this._selections = [value]; this._trySetSelection(true); @@ -391,7 +381,7 @@ class ExtHostTextEditor implements vscode.TextEditor { set selections(value: Selection[]) { if (!Array.isArray(value) || value.some(a => !(a instanceof Selection))) { - throw illegalArg('selections'); + throw illegalArgument('selections'); } this._selections = value; this._trySetSelection(true);