diff --git a/src/vs/base/node/processes.ts b/src/vs/base/node/processes.ts index 40b9365656d983dda51e048365acf69489381e70..6895c7c32b3f338d948358cb08bbad6820cf13d2 100644 --- a/src/vs/base/node/processes.ts +++ b/src/vs/base/node/processes.ts @@ -168,7 +168,7 @@ export abstract class AbstractProcess { public start(): PPromise { if (Platform.isWindows && ((this.options && this.options.cwd && TPath.isUNC(this.options.cwd)) || !this.options && !this.options.cwd && TPath.isUNC(process.cwd()))) { - return Promise.wrapError(nls.localize('TaskRunner.UNC', 'Can\'t execute a shell command on an UNC drive.')); + return Promise.wrapError(new Error(nls.localize('TaskRunner.UNC', 'Can\'t execute a shell command on an UNC drive.'))); } return this.useExec().then((useExec) => { let cc: TValueCallback; diff --git a/src/vs/base/parts/ipc/common/ipc.ts b/src/vs/base/parts/ipc/common/ipc.ts index d581b2dead1d7aa472f52e444281cda839ed0aae..c7b613841d1ad955096e9d7d908f6ef3a221b71c 100644 --- a/src/vs/base/parts/ipc/common/ipc.ts +++ b/src/vs/base/parts/ipc/common/ipc.ts @@ -384,7 +384,7 @@ export class IPCServer implements IChannelServer, IRoutingChannelClient, IDispos const id = router.route(command, arg); if (!id) { - return TPromise.wrapError('Client id should be provided'); + return TPromise.wrapError(new Error('Client id should be provided')); } return this.getClient(id).then(client => client.getChannel(channelName).call(command, arg)); diff --git a/src/vs/base/parts/ipc/node/ipc.cp.ts b/src/vs/base/parts/ipc/node/ipc.cp.ts index 21b1b3f5531270d963cb3f7aeab825d65d201eec..aa2516f86040a18f41a7cbd7ac63e3b2208131a4 100644 --- a/src/vs/base/parts/ipc/node/ipc.cp.ts +++ b/src/vs/base/parts/ipc/node/ipc.cp.ts @@ -95,7 +95,7 @@ export class Client implements IChannelClient, IDisposable { protected request(channelName: string, name: string, arg: any): Promise { if (!this.disposeDelayer) { - return Promise.wrapError('disposed'); + return Promise.wrapError(new Error('disposed')); } this.disposeDelayer.cancel(); diff --git a/src/vs/base/test/common/async.test.ts b/src/vs/base/test/common/async.test.ts index 42075ea137fb3bfd97e835bcbc944512ec1b6925..4c181ef74ba135118a659e22c38e66c72fbffc48 100644 --- a/src/vs/base/test/common/async.test.ts +++ b/src/vs/base/test/common/async.test.ts @@ -495,7 +495,7 @@ suite('Async', () => { let f1 = () => TPromise.as(true).then(() => res.push(1)); let f2 = () => TPromise.timeout(10).then(() => res.push(2)); - let f3 = () => TPromise.as(true).then(() => TPromise.wrapError('error')); + let f3 = () => TPromise.as(true).then(() => TPromise.wrapError(new Error('error'))); let f4 = () => TPromise.timeout(20).then(() => res.push(4)); let f5 = () => TPromise.timeout(0).then(() => res.push(5)); diff --git a/src/vs/base/test/common/cache.test.ts b/src/vs/base/test/common/cache.test.ts index 8a8f1515db2d0ba7c38adc9d0b271479fd8a7327..521c59b3375634a979809c02168a2cba6c88b70d 100644 --- a/src/vs/base/test/common/cache.test.ts +++ b/src/vs/base/test/common/cache.test.ts @@ -23,12 +23,12 @@ suite('Cache', () => { test('simple error', () => { let counter = 0; - const cache = new Cache(() => TPromise.wrapError(counter++)); + const cache = new Cache(() => TPromise.wrapError(new Error(String(counter++)))); return cache.get() - .then(() => assert.fail(), err => assert.equal(err, 0)) + .then(() => assert.fail(), err => assert.equal(err.message, 0)) .then(() => cache.get()) - .then(() => assert.fail(), err => assert.equal(err, 0)); + .then(() => assert.fail(), err => assert.equal(err.message, 0)); }); test('should retry cancellations', () => { diff --git a/src/vs/code/electron-main/main.ts b/src/vs/code/electron-main/main.ts index 8af2717ffec1fd6f6943cb3a2a9fc1948af30ca6..c63e8fa65999aabc9d774d8778ef143cbfed0b2a 100644 --- a/src/vs/code/electron-main/main.ts +++ b/src/vs/code/electron-main/main.ts @@ -109,7 +109,7 @@ function setupIPC(accessor: ServicesAccessor): TPromise { const msg = 'Running extension tests from the command line is currently only supported if no other instance of Code is running.'; console.error(msg); client.dispose(); - return TPromise.wrapError(msg); + return TPromise.wrapError(new Error(msg)); } logService.log('Sending env to running instance...'); @@ -120,7 +120,7 @@ function setupIPC(accessor: ServicesAccessor): TPromise { return allowSetForegroundWindow(service) .then(() => service.start(environmentService.args, process.env)) .then(() => client.dispose()) - .then(() => TPromise.wrapError('Sent env to running instance. Terminating...')); + .then(() => TPromise.wrapError(new Error('Sent env to running instance. Terminating...'))); }, err => { if (!retry || platform.isWindows || err.code !== 'ECONNREFUSED') { diff --git a/src/vs/code/node/cliProcessMain.ts b/src/vs/code/node/cliProcessMain.ts index 5b5c84c0be986f6bca1913b17061a2b04fffa283..99fb1e05f6eedff8e8ff8e701d0a4626a8e2b65c 100644 --- a/src/vs/code/node/cliProcessMain.ts +++ b/src/vs/code/node/cliProcessMain.ts @@ -116,7 +116,7 @@ class Main { const [extension] = result.firstPage; if (!extension) { - return TPromise.wrapError(`${notFound(id)}\n${useId}`); + return TPromise.wrapError(new Error(`${notFound(id)}\n${useId}`)); } console.log(localize('foundExtension', "Found '{0}' in the marketplace.", id)); @@ -137,7 +137,7 @@ class Main { const [extension] = installed.filter(e => getId(e.manifest) === id); if (!extension) { - return TPromise.wrapError(`${notInstalled(id)}\n${useId}`); + return TPromise.wrapError(new Error(`${notInstalled(id)}\n${useId}`)); } console.log(localize('uninstalling', "Uninstalling {0}...", id)); diff --git a/src/vs/editor/common/services/bulkEdit.ts b/src/vs/editor/common/services/bulkEdit.ts index 9916d05ad03b018b4c18ed3a829a8bd3ca14144a..7e60f9069b300fd5c60c3173be8f5326e076e6c2 100644 --- a/src/vs/editor/common/services/bulkEdit.ts +++ b/src/vs/editor/common/services/bulkEdit.ts @@ -338,7 +338,7 @@ export function createBulkEdit(textModelResolverService: ITextModelService, edit let concurrentEdits = getConcurrentEdits(); if (concurrentEdits) { - return TPromise.wrapError(concurrentEdits); + return TPromise.wrapError(new Error(concurrentEdits)); } let uri: URI; diff --git a/src/vs/editor/contrib/links/common/links.ts b/src/vs/editor/contrib/links/common/links.ts index e466535ed0154c7b6a1530608a1acb2abb146b87..047e094293cbaa1cb5c6bb857257cb1b9497e4a2 100644 --- a/src/vs/editor/contrib/links/common/links.ts +++ b/src/vs/editor/contrib/links/common/links.ts @@ -38,7 +38,7 @@ export class Link implements ILink { try { return TPromise.as(URI.parse(this._link.url)); } catch (e) { - return TPromise.wrapError('invalid'); + return TPromise.wrapError(new Error('invalid')); } } @@ -50,11 +50,11 @@ export class Link implements ILink { return this.resolve(); } - return TPromise.wrapError('missing'); + return TPromise.wrapError(new Error('missing')); }); } - return TPromise.wrapError('missing'); + return TPromise.wrapError(new Error('missing')); } } diff --git a/src/vs/editor/contrib/rename/browser/rename.ts b/src/vs/editor/contrib/rename/browser/rename.ts index 92284675cbeb0bbf9432c3d7a307f08c44b315aa..55c51b473cb146a5f83544a14765511a93708104 100644 --- a/src/vs/editor/contrib/rename/browser/rename.ts +++ b/src/vs/editor/contrib/rename/browser/rename.ts @@ -54,7 +54,7 @@ export function rename(model: IReadOnlyModel, position: Position, newName: strin return undefined; }, err => { onUnexpectedExternalError(err); - return TPromise.wrapError('provider failed'); + return TPromise.wrapError(new Error('provider failed')); }); } return undefined; @@ -198,7 +198,7 @@ class RenameController implements IEditorContribution { return rename(this.editor.getModel(), this.editor.getPosition(), newName).then(result => { if (result.rejectReason) { - return TPromise.wrapError(result.rejectReason); + return TPromise.wrapError(new Error(result.rejectReason)); } edit.add(result.edits); return edit; diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 91b3303a2d0d75e90f336231fe0195680d3f2bac..8e0f447643850714f3e421bc93a810c697d19074 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -95,7 +95,7 @@ declare module monaco { public static wrap(value: Thenable): Promise; public static wrap(value: ValueType): Promise; - public static wrapError(error: any): Promise; + public static wrapError(error: Error): Promise; } export class CancellationTokenSource { diff --git a/src/vs/platform/commands/test/commandService.test.ts b/src/vs/platform/commands/test/commandService.test.ts index 24c7558a259a652e04e2518a95e7ab23b6d95872..ea914ea49040a1ccb81a3ea35948f36f5687e02c 100644 --- a/src/vs/platform/commands/test/commandService.test.ts +++ b/src/vs/platform/commands/test/commandService.test.ts @@ -69,12 +69,12 @@ suite('CommandService', function () { let service = new CommandService(new InstantiationService(), new class extends SimpleExtensionService { activateByEvent(activationEvent: string): TPromise { - return TPromise.wrapError('bad_activate'); + return TPromise.wrapError(new Error('bad_activate')); } }); return service.executeCommand('foo').then(() => assert.ok(false), err => { - assert.equal(err, 'bad_activate'); + assert.equal(err.message, 'bad_activate'); }); }); diff --git a/src/vs/platform/extensionManagement/common/extensionEnablementService.ts b/src/vs/platform/extensionManagement/common/extensionEnablementService.ts index ca319bf47b63a81d01959e1232888a9cd5c33871..75606dd0a96a173ea2d7f27600126d22960e2070 100644 --- a/src/vs/platform/extensionManagement/common/extensionEnablementService.ts +++ b/src/vs/platform/extensionManagement/common/extensionEnablementService.ts @@ -61,7 +61,7 @@ export class ExtensionEnablementService implements IExtensionEnablementService { public setEnablement(identifier: string, enable: boolean, workspace: boolean = false): TPromise { if (workspace && !this.hasWorkspace) { - return TPromise.wrapError(localize('noWorkspace', "No workspace.")); + return TPromise.wrapError(new Error(localize('noWorkspace', "No workspace."))); } if (this.environmentService.disableExtensions) { diff --git a/src/vs/platform/extensionManagement/node/extensionGalleryService.ts b/src/vs/platform/extensionManagement/node/extensionGalleryService.ts index 5d31181028c69b33c312e7bc359dff0bbbb57d5c..6b5d9a67ca1b627dee363fd7f3073da7d3628f21 100644 --- a/src/vs/platform/extensionManagement/node/extensionGalleryService.ts +++ b/src/vs/platform/extensionManagement/node/extensionGalleryService.ts @@ -515,7 +515,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService { const firstOptions = assign({}, options, { url: asset.uri }); return this.requestService.request(firstOptions) - .then(context => context.res.statusCode === 200 ? context : TPromise.wrapError('expected 200')) + .then(context => context.res.statusCode === 200 ? context : TPromise.wrapError(new Error('expected 200'))) .then(null, err => { this.telemetryService.publicLog('galleryService:requestError', { cdn: true, message: getErrorMessage(err) }); this.telemetryService.publicLog('galleryService:cdnFallback', { url: asset.uri }); diff --git a/src/vs/platform/extensionManagement/node/extensionManagementService.ts b/src/vs/platform/extensionManagement/node/extensionManagementService.ts index 43b0fb1ed0c082f6b05e1fc756bede27ce46e65b..2fa14e5bf6b41222c10264593edd87e686869445 100644 --- a/src/vs/platform/extensionManagement/node/extensionManagementService.ts +++ b/src/vs/platform/extensionManagement/node/extensionManagementService.ts @@ -368,7 +368,7 @@ export class ExtensionManagementService implements IExtensionManagementService { const dependenciesToUninstall = this.filterDependents(extension, dependencies, installed); let dependents = this.getDependents(extension, installed).filter(dependent => extension !== dependent && dependenciesToUninstall.indexOf(dependent) === -1); if (dependents.length) { - return TPromise.wrapError(this.getDependentsErrorMessage(extension, dependents)); + return TPromise.wrapError(new Error(this.getDependentsErrorMessage(extension, dependents))); } return TPromise.join([this.uninstallExtension(extension.id), ...dependenciesToUninstall.map(d => this.doUninstall(d.id))]).then(() => null); } diff --git a/src/vs/platform/files/common/files.ts b/src/vs/platform/files/common/files.ts index a1565f77403fd2987b9ae75ca78f24bb0da8370e..c78493586986f23ef3497dd8d988d74a5d45f0aa 100644 --- a/src/vs/platform/files/common/files.ts +++ b/src/vs/platform/files/common/files.ts @@ -496,9 +496,10 @@ export interface IImportResult { isNew: boolean; } -export interface IFileOperationResult { - message: string; - fileOperationResult: FileOperationResult; +export class FileOperationError extends Error { + constructor(message: string, public fileOperationResult: FileOperationResult) { + super(message); + } } export enum FileOperationResult { diff --git a/src/vs/platform/message/common/messageIpc.ts b/src/vs/platform/message/common/messageIpc.ts index a6c009e32ec366f0fcf3f42d4c5973bbaa633ab2..069ca25321df5ec6bc45a8ef1f2fe20a0a6f66af 100644 --- a/src/vs/platform/message/common/messageIpc.ts +++ b/src/vs/platform/message/common/messageIpc.ts @@ -23,7 +23,7 @@ export class ChoiceChannel implements IChoiceChannel { switch (command) { case 'choose': return this.choiceService.choose(args[0], args[1], args[2], args[3], args[4]); } - return TPromise.wrapError('invalid command'); + return TPromise.wrapError(new Error('invalid command')); } } diff --git a/src/vs/platform/telemetry/test/electron-browser/telemetryService.test.ts b/src/vs/platform/telemetry/test/electron-browser/telemetryService.test.ts index 099d7bec0885b96321093b3782611ceb656f76de..d435adbd74dcb35f09e49c01ebfb592839e808f5 100644 --- a/src/vs/platform/telemetry/test/electron-browser/telemetryService.test.ts +++ b/src/vs/platform/telemetry/test/electron-browser/telemetryService.test.ts @@ -243,7 +243,7 @@ suite('TelemetryService', () => { // let testAppender = new TestTelemetryAppender(); // service.addTelemetryAppender(testAppender); // - // winjs.Promise.wrapError('This should not get logged'); + // winjs.Promise.wrapError(new Error('This should not get logged')); // winjs.TPromise.as(true).then(() => { // throw new Error('This should get logged'); // }); diff --git a/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts b/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts index 15b4a1ec64947e9740291e5045fa309571640ab8..dc3186f738d2f8876f7811056f5009a7b418b97e 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts @@ -31,13 +31,13 @@ export class MainThreadDebugService extends MainThreadDebugServiceShape { public $createDebugSession(configuration: IConfig): TPromise { if (configuration.request !== 'launch' && configuration.request !== 'attach') { - return TPromise.wrapError(`only 'launch' or 'attach' allowed for 'request' attribute`); + return TPromise.wrapError(new Error(`only 'launch' or 'attach' allowed for 'request' attribute`)); } return this.debugService.createProcess(configuration).then(process => { if (process) { return process.getId(); } - return TPromise.wrapError('cannot create debug session'); + return TPromise.wrapError(new Error('cannot create debug session')); }, err => { return TPromise.wrapError(err && err.message ? err.message : 'cannot create debug session'); }); @@ -50,11 +50,11 @@ export class MainThreadDebugService extends MainThreadDebugServiceShape { if (response.success) { return response.body; } else { - return TPromise.wrapError(response.message); + return TPromise.wrapError(new Error(response.message)); } }); } - return TPromise.wrapError('debug session not found'); + return TPromise.wrapError(new Error('debug session not found')); } private _findProcessByUUID(processId: DebugSessionUUID): IProcess | null { diff --git a/src/vs/workbench/api/electron-browser/mainThreadDocuments.ts b/src/vs/workbench/api/electron-browser/mainThreadDocuments.ts index 83476253ea540bf8a7f9e2250cb8e4b0e6d19752..af6464a5d7dd31114bb854c641db5ea14fcfb92c 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadDocuments.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadDocuments.ts @@ -190,7 +190,7 @@ export class MainThreadDocuments extends MainThreadDocumentsShape { $tryOpenDocument(uri: URI): TPromise { if (!uri.scheme || !(uri.fsPath || uri.authority)) { - return TPromise.wrapError(`Invalid uri. Scheme and authority or path must be set.`); + return TPromise.wrapError(new Error(`Invalid uri. Scheme and authority or path must be set.`)); } let promise: TPromise; @@ -206,11 +206,11 @@ export class MainThreadDocuments extends MainThreadDocumentsShape { return promise.then(success => { if (!success) { - return TPromise.wrapError('cannot open ' + uri.toString()); + return TPromise.wrapError(new Error('cannot open ' + uri.toString())); } return undefined; }, err => { - return TPromise.wrapError('cannot open ' + uri.toString() + '. Detail: ' + toErrorMessage(err)); + return TPromise.wrapError(new Error('cannot open ' + uri.toString() + '. Detail: ' + toErrorMessage(err))); }); } @@ -230,7 +230,7 @@ export class MainThreadDocuments extends MainThreadDocumentsShape { let asFileUri = uri.with({ scheme: 'file' }); return this._fileService.resolveFile(asFileUri).then(stats => { // don't create a new file ontop of an existing file - return TPromise.wrapError('file already exists on disk'); + return TPromise.wrapError(new Error('file already exists on disk')); }, err => this._doCreateUntitled(asFileUri).then(resource => !!resource)); } diff --git a/src/vs/workbench/api/electron-browser/mainThreadEditors.ts b/src/vs/workbench/api/electron-browser/mainThreadEditors.ts index 3de296c7519febdf07af5e3ef4bc784fe2a37995..b1d0589a319636c6ce0ed457cda6623c078863ee 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadEditors.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadEditors.ts @@ -158,7 +158,7 @@ export class MainThreadEditors extends MainThreadEditorsShape { $trySetSelections(id: string, selections: ISelection[]): TPromise { if (!this._documentsAndEditors.getEditor(id)) { - return TPromise.wrapError('TextEditor disposed'); + return TPromise.wrapError(new Error('TextEditor disposed')); } this._documentsAndEditors.getEditor(id).setSelections(selections); return TPromise.as(null); @@ -166,7 +166,7 @@ export class MainThreadEditors extends MainThreadEditorsShape { $trySetDecorations(id: string, key: string, ranges: IDecorationOptions[]): TPromise { if (!this._documentsAndEditors.getEditor(id)) { - return TPromise.wrapError('TextEditor disposed'); + return TPromise.wrapError(new Error('TextEditor disposed')); } this._documentsAndEditors.getEditor(id).setDecorations(key, ranges); return TPromise.as(null); @@ -174,7 +174,7 @@ export class MainThreadEditors extends MainThreadEditorsShape { $tryRevealRange(id: string, range: IRange, revealType: TextEditorRevealType): TPromise { if (!this._documentsAndEditors.getEditor(id)) { - return TPromise.wrapError('TextEditor disposed'); + return TPromise.wrapError(new Error('TextEditor disposed')); } this._documentsAndEditors.getEditor(id).revealRange(range, revealType); return undefined; @@ -182,7 +182,7 @@ export class MainThreadEditors extends MainThreadEditorsShape { $trySetOptions(id: string, options: ITextEditorConfigurationUpdate): TPromise { if (!this._documentsAndEditors.getEditor(id)) { - return TPromise.wrapError('TextEditor disposed'); + return TPromise.wrapError(new Error('TextEditor disposed')); } this._documentsAndEditors.getEditor(id).setConfiguration(options); return TPromise.as(null); @@ -190,14 +190,14 @@ export class MainThreadEditors extends MainThreadEditorsShape { $tryApplyEdits(id: string, modelVersionId: number, edits: ISingleEditOperation[], opts: IApplyEditsOptions): TPromise { if (!this._documentsAndEditors.getEditor(id)) { - return TPromise.wrapError('TextEditor disposed'); + return TPromise.wrapError(new Error('TextEditor disposed')); } return TPromise.as(this._documentsAndEditors.getEditor(id).applyEdits(modelVersionId, edits, opts)); } $tryInsertSnippet(id: string, template: string, ranges: IRange[], opts: IUndoStopOptions): TPromise { if (!this._documentsAndEditors.getEditor(id)) { - return TPromise.wrapError('TextEditor disposed'); + return TPromise.wrapError(new Error('TextEditor disposed')); } return TPromise.as(this._documentsAndEditors.getEditor(id).insertSnippet(template, ranges, opts)); } @@ -214,7 +214,7 @@ export class MainThreadEditors extends MainThreadEditorsShape { const editor = this._documentsAndEditors.getEditor(id); if (!editor) { - return TPromise.wrapError('No such TextEditor'); + return TPromise.wrapError(new Error('No such TextEditor')); } const codeEditor = editor.getCodeEditor(); diff --git a/src/vs/workbench/api/electron-browser/mainThreadSaveParticipant.ts b/src/vs/workbench/api/electron-browser/mainThreadSaveParticipant.ts index db1d0da3b56defc3d2a9b741d0cb61e4531ef091..b1de2a035c92d4cde93e91d5a0499868ae0c36df 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadSaveParticipant.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadSaveParticipant.ts @@ -210,7 +210,7 @@ class ExtHostSaveParticipant implements INamedSaveParticpant { this._proxy.$participateInSave(editorModel.getResource(), env.reason).then(values => { for (const success of values) { if (!success) { - return TPromise.wrapError('listener failed'); + return TPromise.wrapError(new Error('listener failed')); } } return undefined; diff --git a/src/vs/workbench/api/node/extHostApiCommands.ts b/src/vs/workbench/api/node/extHostApiCommands.ts index 16095bd89fc4083b01b681cab81433c9c4b9c60f..bd540c0fa0857b8b82d79f4326859ba8948ad92c 100644 --- a/src/vs/workbench/api/node/extHostApiCommands.ts +++ b/src/vs/workbench/api/node/extHostApiCommands.ts @@ -343,7 +343,7 @@ export class ExtHostApiCommands { return undefined; } if (value.rejectReason) { - return TPromise.wrapError(value.rejectReason); + return TPromise.wrapError(new Error(value.rejectReason)); } let workspaceEdit = new types.WorkspaceEdit(); for (let edit of value.edits) { diff --git a/src/vs/workbench/api/node/extHostCommands.ts b/src/vs/workbench/api/node/extHostCommands.ts index e9c3afe662b64525551969aa2d6cf29dae667262..00ff4f00c4f2faa47c122564c375016275fe4387 100644 --- a/src/vs/workbench/api/node/extHostCommands.ts +++ b/src/vs/workbench/api/node/extHostCommands.ts @@ -104,7 +104,7 @@ export class ExtHostCommands extends ExtHostCommandsShape { $executeContributedCommand(id: string, ...args: any[]): Thenable { let command = this._commands.get(id); if (!command) { - return TPromise.wrapError(`Contributed command '${id}' does not exist.`); + return TPromise.wrapError(new Error(`Contributed command '${id}' does not exist.`)); } let { callback, thisArg, description } = command; @@ -114,7 +114,7 @@ export class ExtHostCommands extends ExtHostCommandsShape { try { validateConstraint(args[i], description.args[i].constraint); } catch (err) { - return TPromise.wrapError(`Running the contributed command:'${id}' failed. Illegal argument '${description.args[i].name}' - ${description.args[i].description}`); + return TPromise.wrapError(new Error(`Running the contributed command:'${id}' failed. Illegal argument '${description.args[i].name}' - ${description.args[i].description}`)); } } } @@ -131,7 +131,7 @@ export class ExtHostCommands extends ExtHostCommandsShape { // } catch (err) { // // // } - return TPromise.wrapError(`Running the contributed command:'${id}' failed.`); + return TPromise.wrapError(new Error(`Running the contributed command:'${id}' failed.`)); } } diff --git a/src/vs/workbench/api/node/extHostDocumentData.ts b/src/vs/workbench/api/node/extHostDocumentData.ts index edb38779935cdf136acd2034b97b613910b5c6ca..e6cd9c2597cdebca51e97635dc3a73ad3a003d17 100644 --- a/src/vs/workbench/api/node/extHostDocumentData.ts +++ b/src/vs/workbench/api/node/extHostDocumentData.ts @@ -101,7 +101,7 @@ export class ExtHostDocumentData extends MirrorModel { private _save(): TPromise { if (this._isDisposed) { - return TPromise.wrapError('Document has been closed'); + return TPromise.wrapError(new Error('Document has been closed')); } return this._proxy.$trySaveDocument(this._uri); } diff --git a/src/vs/workbench/api/node/extHostDocuments.ts b/src/vs/workbench/api/node/extHostDocuments.ts index eacff1334c5cfa7c18365b2f42523f0d5d780b19..745460d188fa422457bdb4b9f51309e9ae7f6e14 100644 --- a/src/vs/workbench/api/node/extHostDocuments.ts +++ b/src/vs/workbench/api/node/extHostDocuments.ts @@ -154,7 +154,7 @@ export class ExtHostDocuments extends ExtHostDocumentsShape { public $provideTextDocumentContent(handle: number, uri: URI): TPromise { const provider = this._documentContentProviders.get(handle); if (!provider) { - return TPromise.wrapError(`unsupported uri-scheme: ${uri.scheme}`); + return TPromise.wrapError(new Error(`unsupported uri-scheme: ${uri.scheme}`)); } return asWinJsPromise(token => provider.provideTextDocumentContent(uri, token)); } diff --git a/src/vs/workbench/api/node/extHostTextEditor.ts b/src/vs/workbench/api/node/extHostTextEditor.ts index b566c23aa34f70071f7d3a565c642ec0d0dbfc08..4bf9f16e274016691115319745fb1fc0b3fd6499 100644 --- a/src/vs/workbench/api/node/extHostTextEditor.ts +++ b/src/vs/workbench/api/node/extHostTextEditor.ts @@ -399,7 +399,7 @@ export class ExtHostTextEditor implements vscode.TextEditor { throw illegalArgument('selection'); } this._selections = [value]; - this._trySetSelection(true); + this._trySetSelection(); } get selections(): Selection[] { @@ -411,7 +411,7 @@ export class ExtHostTextEditor implements vscode.TextEditor { throw illegalArgument('selections'); } this._selections = value; - this._trySetSelection(true); + this._trySetSelection(); } setDecorations(decorationType: vscode.TextEditorDecorationType, ranges: Range[] | vscode.DecorationOptions[]): void { @@ -420,8 +420,7 @@ export class ExtHostTextEditor implements vscode.TextEditor { this._id, decorationType.key, TypeConverters.fromRangeOrRangeWithMessage(ranges) - ), - true + ) ); } @@ -431,14 +430,13 @@ export class ExtHostTextEditor implements vscode.TextEditor { this._id, TypeConverters.fromRange(range), (revealType || TextEditorRevealType.Default) - ), - true + ) ); } - private _trySetSelection(silent: boolean): TPromise { + private _trySetSelection(): TPromise { let selection = this._selections.map(TypeConverters.fromSelection); - return this._runOnProxy(() => this._proxy.$trySetSelections(this._id, selection), silent); + return this._runOnProxy(() => this._proxy.$trySetSelections(this._id, selection)); } _acceptSelections(selections: Selection[]): void { @@ -450,7 +448,7 @@ export class ExtHostTextEditor implements vscode.TextEditor { edit(callback: (edit: TextEditorEdit) => void, options: { undoStopBefore: boolean; undoStopAfter: boolean; } = { undoStopBefore: true, undoStopAfter: true }): Thenable { if (this._disposed) { - return TPromise.wrapError('TextEditor#edit not possible on closed editors'); + return TPromise.wrapError(new Error('TextEditor#edit not possible on closed editors')); } let edit = new TextEditorEdit(this._documentData.document, options); callback(edit); @@ -508,7 +506,7 @@ export class ExtHostTextEditor implements vscode.TextEditor { insertSnippet(snippet: SnippetString, where?: Position | Position[] | Range | Range[], options: { undoStopBefore: boolean; undoStopAfter: boolean; } = { undoStopBefore: true, undoStopAfter: true }): Thenable { if (this._disposed) { - return TPromise.wrapError('TextEditor#insertSnippet not possible on closed editors'); + return TPromise.wrapError(new Error('TextEditor#insertSnippet not possible on closed editors')); } let ranges: IRange[]; @@ -538,19 +536,12 @@ export class ExtHostTextEditor implements vscode.TextEditor { // ---- util - private _runOnProxy(callback: () => TPromise, silent: boolean): TPromise { + private _runOnProxy(callback: () => TPromise): TPromise { if (this._disposed) { - if (!silent) { - return TPromise.wrapError(silent); - } else { - console.warn('TextEditor is closed/disposed'); - return TPromise.as(undefined); - } + console.warn('TextEditor is closed/disposed'); + return TPromise.as(undefined); } return callback().then(() => this, err => { - if (!silent) { - return TPromise.wrapError(silent); - } console.warn(err); return undefined; }); diff --git a/src/vs/workbench/api/node/extHostTreeViews.ts b/src/vs/workbench/api/node/extHostTreeViews.ts index 452e83b8068448123b1fe74f8ff2b99feb611a5a..1999ed6103464814e5f6fd30121f1fe129bf3c37 100644 --- a/src/vs/workbench/api/node/extHostTreeViews.ts +++ b/src/vs/workbench/api/node/extHostTreeViews.ts @@ -53,7 +53,7 @@ export class ExtHostTreeViews extends ExtHostTreeViewsShape { $getElements(treeViewId: string): TPromise { const treeView = this.treeViews.get(treeViewId); if (!treeView) { - return TPromise.wrapError(localize('treeView.notRegistered', 'No tree view with id \'{0}\' registered.', treeViewId)); + return TPromise.wrapError(new Error(localize('treeView.notRegistered', 'No tree view with id \'{0}\' registered.', treeViewId))); } return treeView.getTreeItems(); } @@ -61,7 +61,7 @@ export class ExtHostTreeViews extends ExtHostTreeViewsShape { $getChildren(treeViewId: string, treeItemHandle?: number): TPromise { const treeView = this.treeViews.get(treeViewId); if (!treeView) { - return TPromise.wrapError(localize('treeView.notRegistered', 'No tree view with id \'{0}\' registered.', treeViewId)); + return TPromise.wrapError(new Error(localize('treeView.notRegistered', 'No tree view with id \'{0}\' registered.', treeViewId))); } return treeView.getChildren(treeItemHandle); } @@ -102,7 +102,7 @@ class ExtHostTreeView extends Disposable { if (extElement) { this.clearChildren(extElement); } else { - return TPromise.wrapError(localize('treeItem.notFound', 'No tree item with id \'{0}\' found.', treeItemHandle)); + return TPromise.wrapError(new Error(localize('treeItem.notFound', 'No tree item with id \'{0}\' found.', treeItemHandle))); } return asWinJsPromise(() => this.dataProvider.getChildren(extElement)) @@ -130,7 +130,7 @@ class ExtHostTreeView extends Disposable { elements.filter(element => !!element) .map(element => { if (this.extChildrenElementsMap.has(element)) { - return TPromise.wrapError(localize('treeView.duplicateElement', 'Element {0} is already registered', element)); + return TPromise.wrapError(new Error(localize('treeView.duplicateElement', 'Element {0} is already registered', element))); } return this.resolveElement(element); })) diff --git a/src/vs/workbench/browser/parts/editor/binaryEditor.ts b/src/vs/workbench/browser/parts/editor/binaryEditor.ts index 08ce253c8dbddc9ffd884a27dd1f78c42ec8d174..8771fd8fb880ec8a1a2ec7f72a0400d7b0d2168e 100644 --- a/src/vs/workbench/browser/parts/editor/binaryEditor.ts +++ b/src/vs/workbench/browser/parts/editor/binaryEditor.ts @@ -80,7 +80,7 @@ export abstract class BaseBinaryResourceEditor extends BaseEditor { // Assert Model instance if (!(resolvedModel instanceof BinaryEditorModel)) { - return TPromise.wrapError('Unable to open file as binary'); + return TPromise.wrapError(new Error('Unable to open file as binary')); } // Assert that the current input is still the one we expect. This prevents a race condition when loading takes long and another input was set meanwhile diff --git a/src/vs/workbench/browser/parts/editor/textDiffEditor.ts b/src/vs/workbench/browser/parts/editor/textDiffEditor.ts index 87541968878a93cd9b67824cc2f04f84ab20ab0f..05e105aa0fff211888a66ed2170ff97772b8c566 100644 --- a/src/vs/workbench/browser/parts/editor/textDiffEditor.ts +++ b/src/vs/workbench/browser/parts/editor/textDiffEditor.ts @@ -23,7 +23,7 @@ import { DiffNavigator } from 'vs/editor/browser/widget/diffNavigator'; import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditorWidget'; import { TextDiffEditorModel } from 'vs/workbench/common/editor/textDiffEditorModel'; import { DelegatingWorkbenchEditorService } from 'vs/workbench/services/editor/browser/editorService'; -import { IFileOperationResult, FileOperationResult } from 'vs/platform/files/common/files'; +import { FileOperationError, FileOperationResult } from 'vs/platform/files/common/files'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IStorageService } from 'vs/platform/storage/common/storage'; import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration'; @@ -257,7 +257,7 @@ export class TextDiffEditor extends BaseTextEditor { return errors.some(e => this.isFileBinaryError(e)); } - return (error).fileOperationResult === FileOperationResult.FILE_IS_BINARY; + return (error).fileOperationResult === FileOperationResult.FILE_IS_BINARY; } public clearInput(): void { diff --git a/src/vs/workbench/browser/parts/editor/textResourceEditor.ts b/src/vs/workbench/browser/parts/editor/textResourceEditor.ts index facd8e271d830a380b79cba7d86d0332763ee792..6aa165aa45efaf2a0c4b9e0c3e7a92d152526177 100644 --- a/src/vs/workbench/browser/parts/editor/textResourceEditor.ts +++ b/src/vs/workbench/browser/parts/editor/textResourceEditor.ts @@ -80,7 +80,7 @@ export class TextResourceEditor extends BaseTextEditor { // Assert Model instance if (!(resolvedModel instanceof BaseTextEditorModel)) { - return TPromise.wrapError('Unable to open file as text'); + return TPromise.wrapError(new Error('Unable to open file as text')); } // Assert that the current input is still the one we expect. This prevents a race condition when loading takes long and another input was set meanwhile diff --git a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts index 4a35d8d7648debf74d058d6ff6d3974317bba813..eafaa597a6f84232859a642c22818f053cccf5d9 100644 --- a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts +++ b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts @@ -1002,7 +1002,7 @@ export class QuickOpenController extends Component implements IQuickOpenService return result.then(null, (error) => { delete this.mapResolvedHandlersToPrefix[id]; - return TPromise.wrapError('Unable to instantiate quick open handler ' + handler.moduleName + ' - ' + handler.ctorName + ': ' + JSON.stringify(error)); + return TPromise.wrapError(new Error('Unable to instantiate quick open handler ' + handler.moduleName + ' - ' + handler.ctorName + ': ' + JSON.stringify(error))); }); } diff --git a/src/vs/workbench/common/editor/resourceEditorInput.ts b/src/vs/workbench/common/editor/resourceEditorInput.ts index 0f41e0edc5c776cae8f316d8ddbeadcaa34a974c..3c33a6d16ecbd28da3b226cf327e36c764988151 100644 --- a/src/vs/workbench/common/editor/resourceEditorInput.ts +++ b/src/vs/workbench/common/editor/resourceEditorInput.ts @@ -86,7 +86,7 @@ export class ResourceEditorInput extends EditorInput { if (!(model instanceof ResourceEditorModel)) { ref.dispose(); this.modelReference = null; - return TPromise.wrapError(`Unexpected model for ResourceInput: ${this.resource}`); // TODO@Ben eventually also files should be supported, but we guard due to the dangerous dispose of the model in dispose() + return TPromise.wrapError(new Error(`Unexpected model for ResourceInput: ${this.resource}`)); // TODO@Ben eventually also files should be supported, but we guard due to the dangerous dispose of the model in dispose() } return model; diff --git a/src/vs/workbench/node/extensionHostMain.ts b/src/vs/workbench/node/extensionHostMain.ts index 36507564ad4b347e83fa998251a3e67ba4d698b7..fa79d87f97618c827b652bab3db0764d788b4f92 100644 --- a/src/vs/workbench/node/extensionHostMain.ts +++ b/src/vs/workbench/node/extensionHostMain.ts @@ -200,7 +200,7 @@ export class ExtensionHostMain { this.gracefulExit(1 /* ERROR */); } - return TPromise.wrapError(requireError ? requireError.toString() : nls.localize('extensionTestError', "Path {0} does not point to a valid extension test runner.", this._environment.extensionTestsPath)); + return TPromise.wrapError(new Error(requireError ? requireError.toString() : nls.localize('extensionTestError', "Path {0} does not point to a valid extension test runner.", this._environment.extensionTestsPath))); } private gracefulExit(code: number): void { diff --git a/src/vs/workbench/parts/debug/browser/debugContentProvider.ts b/src/vs/workbench/parts/debug/browser/debugContentProvider.ts index 37ca325f419886bf47c23d56bb13ce08e83d6318..d683f528efa27385c2aa3d76f9f89fa0a46979de 100644 --- a/src/vs/workbench/parts/debug/browser/debugContentProvider.ts +++ b/src/vs/workbench/parts/debug/browser/debugContentProvider.ts @@ -33,7 +33,7 @@ export class DebugContentProvider implements IWorkbenchContribution, ITextModelC const process = this.debugService.getViewModel().focusedProcess; if (!process) { - return TPromise.wrapError(localize('unable', "Unable to resolve the resource without a debug session")); + return TPromise.wrapError(new Error(localize('unable', "Unable to resolve the resource without a debug session"))); } const source = process.sources.get(resource.toString()); let rawSource: DebugProtocol.Source; diff --git a/src/vs/workbench/parts/extensions/node/extensionsWorkbenchService.ts b/src/vs/workbench/parts/extensions/node/extensionsWorkbenchService.ts index eb2226760ca1f3ef49a58c9ecd914f57cc7f8eaa..15cca4f051763f7078e47e7a08380c4cc8a19315 100644 --- a/src/vs/workbench/parts/extensions/node/extensionsWorkbenchService.ts +++ b/src/vs/workbench/parts/extensions/node/extensionsWorkbenchService.ts @@ -188,7 +188,7 @@ class Extension implements IExtension { return readFile(uri.fsPath, 'utf8'); } - return TPromise.wrapError('not available'); + return TPromise.wrapError(new Error('not available')); } getChangelog(): TPromise { @@ -199,7 +199,7 @@ class Extension implements IExtension { const changelogUrl = this.local && this.local.changelogUrl; if (!changelogUrl) { - return TPromise.wrapError('not available'); + return TPromise.wrapError(new Error('not available')); } const uri = URI.parse(changelogUrl); @@ -208,7 +208,7 @@ class Extension implements IExtension { return readFile(uri.fsPath, 'utf8'); } - return TPromise.wrapError('not available'); + return TPromise.wrapError(new Error('not available')); } get dependencies(): string[] { @@ -590,7 +590,7 @@ export class ExtensionsWorkbenchService implements IExtensionsWorkbenchService { if (!enable) { let dependents = this.getDependentsAfterDisablement(extension, dependencies, this.local, workspace); if (dependents.length) { - return TPromise.wrapError(this.getDependentsErrorMessage(extension, dependents)); + return TPromise.wrapError(new Error(this.getDependentsErrorMessage(extension, dependents))); } } return TPromise.join([extension, ...dependencies].map(e => this.doSetEnablement(e, enable, workspace))); diff --git a/src/vs/workbench/parts/files/browser/editors/textFileEditor.ts b/src/vs/workbench/parts/files/browser/editors/textFileEditor.ts index cebb5032438f0342d2e94a946f222523f822d171..77a5b1f6db8e5031431d6a5b9885c6427f378d7c 100644 --- a/src/vs/workbench/parts/files/browser/editors/textFileEditor.ts +++ b/src/vs/workbench/parts/files/browser/editors/textFileEditor.ts @@ -19,7 +19,7 @@ import { BinaryEditorModel } from 'vs/workbench/common/editor/binaryEditorModel' import { FileEditorInput } from 'vs/workbench/parts/files/common/editors/fileEditorInput'; import { ExplorerViewlet } from 'vs/workbench/parts/files/browser/explorerViewlet'; import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; -import { IFileOperationResult, FileOperationResult, FileChangesEvent, IFileService } from 'vs/platform/files/common/files'; +import { FileOperationError, FileOperationResult, FileChangesEvent, IFileService } from 'vs/platform/files/common/files'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import { IStorageService } from 'vs/platform/storage/common/storage'; @@ -158,17 +158,17 @@ export class TextFileEditor extends BaseTextEditor { // In case we tried to open a file inside the text editor and the response // indicates that this is not a text file, reopen the file through the binary // editor. - if ((error).fileOperationResult === FileOperationResult.FILE_IS_BINARY) { + if ((error).fileOperationResult === FileOperationResult.FILE_IS_BINARY) { return this.openAsBinary(input, options); } // Similar, handle case where we were asked to open a folder in the text editor. - if ((error).fileOperationResult === FileOperationResult.FILE_IS_DIRECTORY && this.openAsFolder(input)) { + if ((error).fileOperationResult === FileOperationResult.FILE_IS_DIRECTORY && this.openAsFolder(input)) { return; } // Offer to create a file from the error if we have a file not found and the name is valid - if ((error).fileOperationResult === FileOperationResult.FILE_NOT_FOUND && paths.isValidBasename(paths.basename(input.getResource().fsPath))) { + if ((error).fileOperationResult === FileOperationResult.FILE_NOT_FOUND && paths.isValidBasename(paths.basename(input.getResource().fsPath))) { return TPromise.wrapError(errors.create(toErrorMessage(error), { actions: [ new Action('workbench.files.action.createMissingFile', nls.localize('createFile', "Create File"), null, true, () => { diff --git a/src/vs/workbench/parts/files/browser/fileActions.ts b/src/vs/workbench/parts/files/browser/fileActions.ts index 1c17b189b755a51e9fdde0d9b7cb33baffa40c1a..43d92caa301cb4751df28b5ac10ec1f42dcb679d 100644 --- a/src/vs/workbench/parts/files/browser/fileActions.ts +++ b/src/vs/workbench/parts/files/browser/fileActions.ts @@ -25,7 +25,7 @@ import { dispose, IDisposable } from 'vs/base/common/lifecycle'; import { VIEWLET_ID } from 'vs/workbench/parts/files/common/files'; import labels = require('vs/base/common/labels'); import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; -import { IFileService, IFileStat, IFileOperationResult } from 'vs/platform/files/common/files'; +import { IFileService, IFileStat } from 'vs/platform/files/common/files'; import { toResource, IEditorIdentifier, EditorInput } from 'vs/workbench/common/editor'; import { FileStat, Model, NewStatPlaceholder } from 'vs/workbench/parts/files/common/explorerModel'; import { ExplorerView } from 'vs/workbench/parts/files/browser/views/explorerView'; @@ -76,9 +76,8 @@ export class BaseErrorReportingAction extends Action { } protected onError(error: any): void { - const fileOperation = error as IFileOperationResult; - if (typeof fileOperation.message === 'string') { - error = fileOperation.message; + if (error.message === 'string') { + error = error.message; } this._messageService.show(Severity.Error, toErrorMessage(error, false)); @@ -172,17 +171,17 @@ export class TriggerRenameFileAction extends BaseFileAction { public run(context?: any): TPromise { if (!context) { - return TPromise.wrapError('No context provided to BaseEnableFileRenameAction.'); + return TPromise.wrapError(new Error('No context provided to BaseEnableFileRenameAction.')); } const viewletState = context.viewletState; if (!viewletState) { - return TPromise.wrapError('Invalid viewlet state provided to BaseEnableFileRenameAction.'); + return TPromise.wrapError(new Error('Invalid viewlet state provided to BaseEnableFileRenameAction.')); } const stat = context.stat; if (!stat) { - return TPromise.wrapError('Invalid stat provided to BaseEnableFileRenameAction.'); + return TPromise.wrapError(new Error('Invalid stat provided to BaseEnableFileRenameAction.')); } viewletState.setEditable(stat, { @@ -235,12 +234,12 @@ export abstract class BaseRenameAction extends BaseFileAction { public run(context?: any): TPromise { if (!context) { - return TPromise.wrapError('No context provided to BaseRenameFileAction.'); + return TPromise.wrapError(new Error('No context provided to BaseRenameFileAction.')); } let name = context.value; if (!name) { - return TPromise.wrapError('No new name provided to BaseRenameFileAction.'); + return TPromise.wrapError(new Error('No new name provided to BaseRenameFileAction.')); } // Automatically trim whitespaces and trailing dots to produce nice file names @@ -369,12 +368,12 @@ export class BaseNewAction extends BaseFileAction { public run(context?: any): TPromise { if (!context) { - return TPromise.wrapError('No context provided to BaseNewAction.'); + return TPromise.wrapError(new Error('No context provided to BaseNewAction.')); } const viewletState = context.viewletState; if (!viewletState) { - return TPromise.wrapError('Invalid viewlet state provided to BaseNewAction.'); + return TPromise.wrapError(new Error('Invalid viewlet state provided to BaseNewAction.')); } let folder = this.presetFolder; @@ -389,7 +388,7 @@ export class BaseNewAction extends BaseFileAction { } if (!folder) { - return TPromise.wrapError('Invalid parent folder to create.'); + return TPromise.wrapError(new Error('Invalid parent folder to create.')); } return this.tree.reveal(folder, 0.5).then(() => { diff --git a/src/vs/workbench/parts/files/browser/saveErrorHandler.ts b/src/vs/workbench/parts/files/browser/saveErrorHandler.ts index a4e45da21d89d1affac8119807f766f5f8d82eb5..9c655cc1e57df2f27a74db263a2b8fd3b14d9712 100644 --- a/src/vs/workbench/parts/files/browser/saveErrorHandler.ts +++ b/src/vs/workbench/parts/files/browser/saveErrorHandler.ts @@ -12,7 +12,7 @@ import paths = require('vs/base/common/paths'); import { Action } from 'vs/base/common/actions'; import URI from 'vs/base/common/uri'; import { SaveFileAsAction, RevertFileAction, SaveFileAction } from 'vs/workbench/parts/files/browser/fileActions'; -import { IFileOperationResult, FileOperationResult } from 'vs/platform/files/common/files'; +import { FileOperationError, FileOperationResult } from 'vs/platform/files/common/files'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; import { ITextFileService, ISaveErrorHandler, ITextFileEditorModel } from 'vs/workbench/services/textfile/common/textfiles'; @@ -116,13 +116,13 @@ export class SaveErrorHandler implements ISaveErrorHandler, IWorkbenchContributi const resource = model.getResource(); // Dirty write prevention - if ((error).fileOperationResult === FileOperationResult.FILE_MODIFIED_SINCE) { + if ((error).fileOperationResult === FileOperationResult.FILE_MODIFIED_SINCE) { message = this.instantiationService.createInstance(ResolveSaveConflictMessage, model, null); } // Any other save error else { - const isReadonly = (error).fileOperationResult === FileOperationResult.FILE_READ_ONLY; + const isReadonly = (error).fileOperationResult === FileOperationResult.FILE_READ_ONLY; const actions: Action[] = []; // Save As diff --git a/src/vs/workbench/parts/files/browser/views/explorerViewer.ts b/src/vs/workbench/parts/files/browser/views/explorerViewer.ts index d31ba8ec2ff315e63453bec3c47a35826daee4a5..eb189012f9112450fd8a120768d17301a3fbe39b 100644 --- a/src/vs/workbench/parts/files/browser/views/explorerViewer.ts +++ b/src/vs/workbench/parts/files/browser/views/explorerViewer.ts @@ -25,7 +25,7 @@ import { IDisposable } from 'vs/base/common/lifecycle'; import { ContributableActionProvider } from 'vs/workbench/browser/actions'; import { IFilesConfiguration } from 'vs/workbench/parts/files/common/files'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; -import { IFileOperationResult, FileOperationResult, IFileService } from 'vs/platform/files/common/files'; +import { FileOperationError, FileOperationResult, IFileService } from 'vs/platform/files/common/files'; import { ResourceMap } from 'vs/base/common/map'; import { DuplicateFileAction, ImportFileAction, IEditableData, IFileViewletState } from 'vs/workbench/parts/files/browser/fileActions'; import { IDataSource, ITree, IAccessibilityProvider, IRenderer, ContextMenuEvent, ISorter, IFilter, IDragAndDrop, IDragAndDropData, IDragOverReaction, DRAG_OVER_ACCEPT_BUBBLE_DOWN, DRAG_OVER_ACCEPT_BUBBLE_DOWN_COPY, DRAG_OVER_ACCEPT_BUBBLE_UP, DRAG_OVER_ACCEPT_BUBBLE_UP_COPY, DRAG_OVER_REJECT } from 'vs/base/parts/tree/browser/tree'; @@ -823,7 +823,7 @@ export class FileDragAndDrop implements IDragAndDrop { return this.fileService.moveFile(source.resource, targetResource).then(null, error => { // Conflict - if ((error).fileOperationResult === FileOperationResult.FILE_MOVE_CONFLICT) { + if ((error).fileOperationResult === FileOperationResult.FILE_MOVE_CONFLICT) { didHandleConflict = true; const confirm: IConfirmation = { diff --git a/src/vs/workbench/parts/files/common/editors/fileEditorInput.ts b/src/vs/workbench/parts/files/common/editors/fileEditorInput.ts index d38198bb83370fc231e66a02a82d5e422762c87e..8700ed4ecdd04dd40d804f4e94082e89836f44b4 100644 --- a/src/vs/workbench/parts/files/common/editors/fileEditorInput.ts +++ b/src/vs/workbench/parts/files/common/editors/fileEditorInput.ts @@ -12,7 +12,7 @@ import URI from 'vs/base/common/uri'; import { EncodingMode, ConfirmResult, EditorInput, IFileEditorInput, ITextEditorModel } from 'vs/workbench/common/editor'; import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel'; import { BinaryEditorModel } from 'vs/workbench/common/editor/binaryEditorModel'; -import { IFileOperationResult, FileOperationResult } from 'vs/platform/files/common/files'; +import { FileOperationError, FileOperationResult } from 'vs/platform/files/common/files'; import { BINARY_FILE_EDITOR_ID, TEXT_FILE_EDITOR_ID, FILE_EDITOR_INPUT_ID } from 'vs/workbench/parts/files/common/files'; import { ITextFileService, AutoSaveMode, ModelState, TextFileModelChangeEvent } from 'vs/workbench/services/textfile/common/textfiles'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; @@ -216,7 +216,7 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput { }, error => { // In case of an error that indicates that the file is binary or too large, just return with the binary editor model - if ((error).fileOperationResult === FileOperationResult.FILE_IS_BINARY || (error).fileOperationResult === FileOperationResult.FILE_TOO_LARGE) { + if ((error).fileOperationResult === FileOperationResult.FILE_IS_BINARY || (error).fileOperationResult === FileOperationResult.FILE_TOO_LARGE) { return this.resolveAsBinary(); } diff --git a/src/vs/workbench/parts/files/test/browser/fileEditorInput.test.ts b/src/vs/workbench/parts/files/test/browser/fileEditorInput.test.ts index f450854acedd8e6761805d867071d670925be21f..4f19a7f53e86c56094b116e07213d67350599c8a 100644 --- a/src/vs/workbench/parts/files/test/browser/fileEditorInput.test.ts +++ b/src/vs/workbench/parts/files/test/browser/fileEditorInput.test.ts @@ -13,7 +13,7 @@ import { workbenchInstantiationService, TestTextFileService, TestEditorGroupServ import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { EncodingMode } from 'vs/workbench/common/editor'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; -import { FileOperationResult, IFileOperationResult } from 'vs/platform/files/common/files'; +import { FileOperationResult, FileOperationError } from 'vs/platform/files/common/files'; import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel'; import { Verbosity } from 'vs/platform/editor/common/editor'; import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService'; @@ -173,10 +173,7 @@ suite('Files - FileEditorInput', () => { test('resolve handles binary files', function (done) { const input = instantiationService.createInstance(FileEditorInput, toResource.call(this, '/foo/bar/updatefile.js'), void 0); - accessor.textFileService.setResolveTextContentErrorOnce({ - message: 'error', - fileOperationResult: FileOperationResult.FILE_IS_BINARY - }); + accessor.textFileService.setResolveTextContentErrorOnce(new FileOperationError('error', FileOperationResult.FILE_IS_BINARY)); return input.resolve(true).then(resolved => { assert.ok(resolved); diff --git a/src/vs/workbench/parts/html/browser/htmlPreviewPart.ts b/src/vs/workbench/parts/html/browser/htmlPreviewPart.ts index cf8a9c9fe40325a3dc98987bcd279709ac963a72..5be86efec4989a8c99475ca9cd8fa67de0eca9c5 100644 --- a/src/vs/workbench/parts/html/browser/htmlPreviewPart.ts +++ b/src/vs/workbench/parts/html/browser/htmlPreviewPart.ts @@ -194,7 +194,7 @@ export class HtmlPreviewPart extends WebviewEditor { this._modelChangeSubscription.dispose(); if (!(input instanceof HtmlInput)) { - return TPromise.wrapError('Invalid input'); + return TPromise.wrapError(new Error('Invalid input')); } return super.setInput(input, options).then(() => { @@ -207,7 +207,7 @@ export class HtmlPreviewPart extends WebviewEditor { } if (!this.model) { - return TPromise.wrapError(localize('html.voidInput', "Invalid editor input.")); + return TPromise.wrapError(new Error(localize('html.voidInput', "Invalid editor input."))); } this._modelChangeSubscription = this.model.onDidChangeContent(() => { diff --git a/src/vs/workbench/parts/preferences/browser/preferencesRenderers.ts b/src/vs/workbench/parts/preferences/browser/preferencesRenderers.ts index 76f8884d71af32b1bd6310123c24be728ff3eb90..2cfc95fbb379ca13b121d1095618611cc1744333 100644 --- a/src/vs/workbench/parts/preferences/browser/preferencesRenderers.ts +++ b/src/vs/workbench/parts/preferences/browser/preferencesRenderers.ts @@ -22,7 +22,7 @@ import { IContextMenuService, ContextSubMenu } from 'vs/platform/contextview/bro import { SettingsGroupTitleWidget, EditPreferenceWidget, SettingsHeaderWidget } from 'vs/workbench/parts/preferences/browser/preferencesWidgets'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { RangeHighlightDecorations } from 'vs/workbench/common/editor/rangeDecorations'; -import { IConfigurationEditingService, IConfigurationEditingError, ConfigurationEditingErrorCode, ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing'; +import { IConfigurationEditingService, ConfigurationEditingError, ConfigurationEditingErrorCode, ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { overrideIdentifierFromKey } from 'vs/platform/configuration/common/model'; import { IMarkerService, IMarkerData } from 'vs/platform/markers/common/markers'; @@ -100,7 +100,7 @@ export class UserSettingsRenderer extends Disposable implements IPreferencesRend }); } - private toErrorMessage(error: IConfigurationEditingError, target: ConfigurationTarget): string { + private toErrorMessage(error: ConfigurationEditingError, target: ConfigurationTarget): string { switch (error.code) { case ConfigurationEditingErrorCode.ERROR_INVALID_CONFIGURATION: { return nls.localize('errorInvalidConfiguration', "Unable to write into settings. Correct errors/warnings in the file and try again."); diff --git a/src/vs/workbench/parts/preferences/browser/preferencesService.ts b/src/vs/workbench/parts/preferences/browser/preferencesService.ts index 05b44bc620dbb6296e3cdeaa71087254677c5ca3..6e09930623130795b11654581a7cb5cbcc413a17 100644 --- a/src/vs/workbench/parts/preferences/browser/preferencesService.ts +++ b/src/vs/workbench/parts/preferences/browser/preferencesService.ts @@ -20,7 +20,7 @@ import { Position as EditorPosition, IEditor } from 'vs/platform/editor/common/e import { ICommonCodeEditor } from 'vs/editor/common/editorCommon'; import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService'; import { IStorageService } from 'vs/platform/storage/common/storage'; -import { IFileService, IFileOperationResult, FileOperationResult } from 'vs/platform/files/common/files'; +import { IFileService, FileOperationError, FileOperationResult } from 'vs/platform/files/common/files'; import { IMessageService, Severity, IChoiceService } from 'vs/platform/message/common/message'; import { IExtensionService } from 'vs/platform/extensions/common/extensions'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; @@ -269,7 +269,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic private createIfNotExists(resource: URI, contents: string): TPromise { return this.fileService.resolveContent(resource, { acceptTextOnly: true }).then(null, error => { - if ((error).fileOperationResult === FileOperationResult.FILE_NOT_FOUND) { + if ((error).fileOperationResult === FileOperationResult.FILE_NOT_FOUND) { return this.fileService.updateContent(resource, contents).then(null, error => { return TPromise.wrapError(new Error(nls.localize('fail.createSettings', "Unable to create '{0}' ({1}).", labels.getPathLabel(resource, this.contextService, this.environmentService), error))); }); diff --git a/src/vs/workbench/parts/tasks/node/processTaskSystem.ts b/src/vs/workbench/parts/tasks/node/processTaskSystem.ts index f45236b181be36a70611ce406df72bbfae62b9cd..da8779d160b829e109d26ac40f7ba633dc47e82f 100644 --- a/src/vs/workbench/parts/tasks/node/processTaskSystem.ts +++ b/src/vs/workbench/parts/tasks/node/processTaskSystem.ts @@ -280,27 +280,32 @@ export class ProcessTaskSystem extends EventEmitter implements ITaskSystem { this.activeTaskPromise = null; } - private handleError(task: Task, error: ErrorData): Promise { + private handleError(task: Task, errorData: ErrorData): Promise { let makeVisible = false; - if (error.error && !error.terminated) { + if (errorData.error && !errorData.terminated) { let args: string = task.command.args ? task.command.args.join(' ') : ''; this.log(nls.localize('TaskRunnerSystem.childProcessError', 'Failed to launch external program {0} {1}.', task.command.name, args)); - this.outputChannel.append(error.error.message); + this.outputChannel.append(errorData.error.message); makeVisible = true; } - if (error.stdout) { - this.outputChannel.append(error.stdout); + if (errorData.stdout) { + this.outputChannel.append(errorData.stdout); makeVisible = true; } - if (error.stderr) { - this.outputChannel.append(error.stderr); + if (errorData.stderr) { + this.outputChannel.append(errorData.stderr); makeVisible = true; } - makeVisible = this.checkTerminated(task, error) || makeVisible; + makeVisible = this.checkTerminated(task, errorData) || makeVisible; if (makeVisible) { this.showOutput(); } + + const error: Error & ErrorData = errorData.error || new Error(); + error.stderr = errorData.stderr; + error.stdout = errorData.stdout; + error.terminated = errorData.terminated; return Promise.wrapError(error); } diff --git a/src/vs/workbench/parts/update/electron-browser/update.ts b/src/vs/workbench/parts/update/electron-browser/update.ts index bab0d176d233a153ccfae8c61ac063c70028184a..f0faf44a7ce6b94d36a497902f63389e219c9d6b 100644 --- a/src/vs/workbench/parts/update/electron-browser/update.ts +++ b/src/vs/workbench/parts/update/electron-browser/update.ts @@ -57,7 +57,7 @@ export function loadReleaseNotes(accessor: ServicesAccessor, version: string): T const match = /^(\d+\.\d+)\./.exec(version); if (!match) { - return TPromise.wrapError('not found'); + return TPromise.wrapError(new Error('not found')); } const versionLabel = match[1].replace(/\./g, '_'); diff --git a/src/vs/workbench/services/configuration/common/configurationEditing.ts b/src/vs/workbench/services/configuration/common/configurationEditing.ts index df7c2650481876f586f70f09f42476468ff0d150..415e2e58d9ec24e8d7145d488f53a4333979a40c 100644 --- a/src/vs/workbench/services/configuration/common/configurationEditing.ts +++ b/src/vs/workbench/services/configuration/common/configurationEditing.ts @@ -38,9 +38,10 @@ export enum ConfigurationEditingErrorCode { ERROR_INVALID_CONFIGURATION } -export interface IConfigurationEditingError { - code: ConfigurationEditingErrorCode; - message: string; +export class ConfigurationEditingError extends Error { + constructor(message: string, public code: ConfigurationEditingErrorCode) { + super(message); + } } export enum ConfigurationTarget { diff --git a/src/vs/workbench/services/configuration/node/configurationEditingService.ts b/src/vs/workbench/services/configuration/node/configurationEditingService.ts index 19c41e19c88d2a15ee3410c6c40a1c9f26b35e05..f211b663daa9fcb3004de2e5e60b580eb30990d9 100644 --- a/src/vs/workbench/services/configuration/node/configurationEditingService.ts +++ b/src/vs/workbench/services/configuration/node/configurationEditingService.ts @@ -27,7 +27,7 @@ import { IConfigurationService, IConfigurationOverrides } from 'vs/platform/conf import { keyFromOverrideIdentifier } from 'vs/platform/configuration/common/model'; import { WORKSPACE_CONFIG_DEFAULT_PATH, WORKSPACE_STANDALONE_CONFIGURATIONS } from 'vs/workbench/services/configuration/common/configuration'; import { IFileService } from 'vs/platform/files/common/files'; -import { IConfigurationEditingService, ConfigurationEditingErrorCode, IConfigurationEditingError, ConfigurationTarget, IConfigurationValue, IConfigurationEditingOptions } from 'vs/workbench/services/configuration/common/configurationEditing'; +import { IConfigurationEditingService, ConfigurationEditingErrorCode, ConfigurationEditingError, ConfigurationTarget, IConfigurationValue, IConfigurationEditingOptions } from 'vs/workbench/services/configuration/common/configurationEditing'; import { ITextModelService, ITextEditorModel } from 'vs/editor/common/services/resolverService'; import { OVERRIDE_PROPERTY_PATTERN } from 'vs/platform/configuration/common/configurationRegistry'; import { IChoiceService, IMessageService, Severity } from 'vs/platform/message/common/message'; @@ -72,7 +72,10 @@ export class ConfigurationEditingService implements IConfigurationEditingService return this.queue.queue(() => this.doWriteConfiguration(target, value, options) // queue up writes to prevent race conditions .then(() => null, error => { - return options.donotNotifyError ? TPromise.wrapError(error) : this.onError(error, target, value, options.scopes); + if (!options.donotNotifyError) { + this.onError(error, target, value, options.scopes); + } + return TPromise.wrapError(error); })); } @@ -108,7 +111,7 @@ export class ConfigurationEditingService implements IConfigurationEditingService return false; } - private onError(error: IConfigurationEditingError, target: ConfigurationTarget, value: IConfigurationValue, scopes: IConfigurationOverrides): TPromise { + private onError(error: ConfigurationEditingError, target: ConfigurationTarget, value: IConfigurationValue, scopes: IConfigurationOverrides): void { switch (error.code) { case ConfigurationEditingErrorCode.ERROR_INVALID_CONFIGURATION: this.onInvalidConfigurationError(error, target); @@ -119,10 +122,9 @@ export class ConfigurationEditingService implements IConfigurationEditingService default: this.messageService.show(Severity.Error, error.message); } - return TPromise.wrapError(error); } - private onInvalidConfigurationError(error: IConfigurationEditingError, target: ConfigurationTarget): void { + private onInvalidConfigurationError(error: ConfigurationEditingError, target: ConfigurationTarget): void { this.choiceService.choose(Severity.Error, error.message, [nls.localize('open', "Open Settings"), nls.localize('close', "Close")], 1) .then(option => { switch (option) { @@ -132,7 +134,7 @@ export class ConfigurationEditingService implements IConfigurationEditingService }); } - private onConfigurationFileDirtyError(error: IConfigurationEditingError, target: ConfigurationTarget, value: IConfigurationValue, scopes: IConfigurationOverrides): void { + private onConfigurationFileDirtyError(error: ConfigurationEditingError, target: ConfigurationTarget, value: IConfigurationValue, scopes: IConfigurationOverrides): void { this.choiceService.choose(Severity.Error, error.message, [nls.localize('saveAndRetry', "Save Settings and Retry"), nls.localize('open', "Open Settings"), nls.localize('close', "Close")], 2) .then(option => { switch (option) { @@ -150,14 +152,10 @@ export class ConfigurationEditingService implements IConfigurationEditingService this.commandService.executeCommand(ConfigurationTarget.USER === target ? 'workbench.action.openGlobalSettings' : 'workbench.action.openWorkspaceSettings'); } - private wrapError(code: ConfigurationEditingErrorCode, target: ConfigurationTarget): TPromise { + private wrapError(code: ConfigurationEditingErrorCode, target: ConfigurationTarget): TPromise { const message = this.toErrorMessage(code, target); - return TPromise.wrapError({ - code, - message, - toString: () => message - }); + return TPromise.wrapError(new ConfigurationEditingError(message, code)); } private toErrorMessage(error: ConfigurationEditingErrorCode, target: ConfigurationTarget): string { diff --git a/src/vs/workbench/services/configuration/test/node/configurationEditingService.test.ts b/src/vs/workbench/services/configuration/test/node/configurationEditingService.test.ts index 17d1278ac4efcdb4c423becf5b245fffe573f32e..bf628895ee9f737ad771b4a20e553c60109ca8e6 100644 --- a/src/vs/workbench/services/configuration/test/node/configurationEditingService.test.ts +++ b/src/vs/workbench/services/configuration/test/node/configurationEditingService.test.ts @@ -25,7 +25,7 @@ import { WorkspaceConfigurationService } from 'vs/workbench/services/configurati import URI from 'vs/base/common/uri'; import { FileService } from 'vs/workbench/services/files/node/fileService'; import { ConfigurationEditingService } from 'vs/workbench/services/configuration/node/configurationEditingService'; -import { ConfigurationTarget, IConfigurationEditingError, ConfigurationEditingErrorCode } from 'vs/workbench/services/configuration/common/configurationEditing'; +import { ConfigurationTarget, ConfigurationEditingError, ConfigurationEditingErrorCode } from 'vs/workbench/services/configuration/common/configurationEditing'; import { IFileService } from 'vs/platform/files/common/files'; import { WORKSPACE_STANDALONE_CONFIGURATIONS } from 'vs/workbench/services/configuration/common/configuration'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; @@ -171,34 +171,34 @@ suite('ConfigurationEditingService', () => { test('errors cases - invalid key', () => { return testObject.writeConfiguration(ConfigurationTarget.WORKSPACE, { key: 'unknown.key', value: 'value' }) .then(() => assert.fail('Should fail with ERROR_UNKNOWN_KEY'), - (error: IConfigurationEditingError) => assert.equal(error.code, ConfigurationEditingErrorCode.ERROR_UNKNOWN_KEY)); + (error: ConfigurationEditingError) => assert.equal(error.code, ConfigurationEditingErrorCode.ERROR_UNKNOWN_KEY)); }); test('errors cases - invalid target', () => { return testObject.writeConfiguration(ConfigurationTarget.USER, { key: 'tasks.something', value: 'value' }) .then(() => assert.fail('Should fail with ERROR_INVALID_TARGET'), - (error: IConfigurationEditingError) => assert.equal(error.code, ConfigurationEditingErrorCode.ERROR_INVALID_TARGET)); + (error: ConfigurationEditingError) => assert.equal(error.code, ConfigurationEditingErrorCode.ERROR_INVALID_TARGET)); }); test('errors cases - no workspace', () => { return setUpServices(true) .then(() => testObject.writeConfiguration(ConfigurationTarget.WORKSPACE, { key: 'configurationEditing.service.testSetting', value: 'value' })) .then(() => assert.fail('Should fail with ERROR_NO_WORKSPACE_OPENED'), - (error: IConfigurationEditingError) => assert.equal(error.code, ConfigurationEditingErrorCode.ERROR_NO_WORKSPACE_OPENED)); + (error: ConfigurationEditingError) => assert.equal(error.code, ConfigurationEditingErrorCode.ERROR_NO_WORKSPACE_OPENED)); }); test('errors cases - invalid configuration', () => { fs.writeFileSync(globalSettingsFile, ',,,,,,,,,,,,,,'); return testObject.writeConfiguration(ConfigurationTarget.USER, { key: 'configurationEditing.service.testSetting', value: 'value' }) .then(() => assert.fail('Should fail with ERROR_INVALID_CONFIGURATION'), - (error: IConfigurationEditingError) => assert.equal(error.code, ConfigurationEditingErrorCode.ERROR_INVALID_CONFIGURATION)); + (error: ConfigurationEditingError) => assert.equal(error.code, ConfigurationEditingErrorCode.ERROR_INVALID_CONFIGURATION)); }); test('errors cases - dirty', () => { instantiationService.stub(ITextFileService, 'isDirty', true); return testObject.writeConfiguration(ConfigurationTarget.USER, { key: 'configurationEditing.service.testSetting', value: 'value' }) .then(() => assert.fail('Should fail with ERROR_CONFIGURATION_FILE_DIRTY error.'), - (error: IConfigurationEditingError) => assert.equal(error.code, ConfigurationEditingErrorCode.ERROR_CONFIGURATION_FILE_DIRTY)); + (error: ConfigurationEditingError) => assert.equal(error.code, ConfigurationEditingErrorCode.ERROR_CONFIGURATION_FILE_DIRTY)); }); test('dirty error is not thrown if not asked to save', () => { @@ -213,7 +213,7 @@ suite('ConfigurationEditingService', () => { instantiationService.stubPromise(IChoiceService, 'choose', target); return testObject.writeConfiguration(ConfigurationTarget.USER, { key: 'configurationEditing.service.testSetting', value: 'value' }, { donotNotifyError: true }) .then(() => assert.fail('Should fail with ERROR_CONFIGURATION_FILE_DIRTY error.'), - (error: IConfigurationEditingError) => { + (error: ConfigurationEditingError) => { assert.equal(false, target.calledOnce); assert.equal(error.code, ConfigurationEditingErrorCode.ERROR_CONFIGURATION_FILE_DIRTY); }); diff --git a/src/vs/workbench/services/files/node/fileService.ts b/src/vs/workbench/services/files/node/fileService.ts index c9c6645456c5b4fc718b46c7f164227ead6b44dc..5c9874d4c28d2e4c514bb276a472b07fd5b52ccc 100644 --- a/src/vs/workbench/services/files/node/fileService.ts +++ b/src/vs/workbench/services/files/node/fileService.ts @@ -11,7 +11,7 @@ import os = require('os'); import crypto = require('crypto'); import assert = require('assert'); -import { isParent, FileOperation, FileOperationEvent, IContent, IFileService, IResolveFileOptions, IResolveContentOptions, IFileStat, IStreamContent, IFileOperationResult, FileOperationResult, IUpdateContentOptions, FileChangeType, IImportResult, MAX_FILE_SIZE, FileChangesEvent, IFilesConfiguration } from 'vs/platform/files/common/files'; +import { isParent, FileOperation, FileOperationEvent, IContent, IFileService, IResolveFileOptions, IResolveContentOptions, IFileStat, IStreamContent, FileOperationError, FileOperationResult, IUpdateContentOptions, FileChangeType, IImportResult, MAX_FILE_SIZE, FileChangesEvent, IFilesConfiguration } from 'vs/platform/files/common/files'; import { isEqualOrParent } from 'vs/base/common/paths'; import { ResourceMap } from 'vs/base/common/map'; import arrays = require('vs/base/common/arrays'); @@ -217,10 +217,10 @@ export class FileService implements IFileService { // Guard early against attempts to resolve an invalid file path if (resource.scheme !== 'file' || !resource.fsPath) { - return TPromise.wrapError({ - message: nls.localize('fileInvalidPath', "Invalid file resource ({0})", resource.toString()), - fileOperationResult: FileOperationResult.FILE_INVALID_PATH - }); + return TPromise.wrapError(new FileOperationError( + nls.localize('fileInvalidPath', "Invalid file resource ({0})", resource.toString()), + FileOperationResult.FILE_INVALID_PATH + )); } // 1.) resolve resource @@ -228,26 +228,20 @@ export class FileService implements IFileService { // Return early if resource is a directory if (model.isDirectory) { - return TPromise.wrapError({ - message: nls.localize('fileIsDirectoryError', "File is directory ({0})", absolutePath), - fileOperationResult: FileOperationResult.FILE_IS_DIRECTORY - }); + return TPromise.wrapError(new FileOperationError( + nls.localize('fileIsDirectoryError', "File is directory ({0})", absolutePath), + FileOperationResult.FILE_IS_DIRECTORY + )); } // Return early if file not modified since if (options && options.etag && options.etag === model.etag) { - return TPromise.wrapError({ - message: nls.localize('fileNotModifiedError', "File not modified since"), - fileOperationResult: FileOperationResult.FILE_NOT_MODIFIED_SINCE - }); + return TPromise.wrapError(new FileOperationError(nls.localize('fileNotModifiedError', "File not modified since"), FileOperationResult.FILE_NOT_MODIFIED_SINCE)); } // Return early if file is too large to load if (types.isNumber(model.size) && model.size > MAX_FILE_SIZE) { - return TPromise.wrapError({ - message: nls.localize('fileTooLargeError', "File too large to open"), - fileOperationResult: FileOperationResult.FILE_TOO_LARGE - }); + return TPromise.wrapError(new FileOperationError(nls.localize('fileTooLargeError', "File too large to open"), FileOperationResult.FILE_TOO_LARGE)); } // 2.) detect mimes @@ -257,10 +251,10 @@ export class FileService implements IFileService { // Return error early if client only accepts text and this is not text if (options && options.acceptTextOnly && !isText) { - return TPromise.wrapError({ - message: nls.localize('fileBinaryError', "File seems to be binary and cannot be opened as text"), - fileOperationResult: FileOperationResult.FILE_IS_BINARY - }); + return TPromise.wrapError(new FileOperationError( + nls.localize('fileBinaryError', "File seems to be binary and cannot be opened as text"), + FileOperationResult.FILE_IS_BINARY + )); } let preferredEncoding: string; @@ -286,7 +280,7 @@ export class FileService implements IFileService { }, (error) => { // bubble up existing file operation results - if (!types.isUndefinedOrNull((error).fileOperationResult)) { + if (!types.isUndefinedOrNull((error).fileOperationResult)) { return TPromise.wrapError(error); } @@ -295,10 +289,10 @@ export class FileService implements IFileService { // Return if file not found if (!exists) { - return TPromise.wrapError({ - message: nls.localize('fileNotFoundError', "File not found ({0})", absolutePath), - fileOperationResult: FileOperationResult.FILE_NOT_FOUND - }); + return TPromise.wrapError(new FileOperationError( + nls.localize('fileNotFoundError', "File not found ({0})", absolutePath), + FileOperationResult.FILE_NOT_FOUND + )); } // otherwise just give up @@ -472,17 +466,14 @@ export class FileService implements IFileService { // Return early with conflict if target exists and we are not told to overwrite if (exists && !isCaseRename && !overwrite) { - return TPromise.wrapError({ - message: nls.localize('fileMoveConflict', "Unable to move/copy. File already exists at destination."), - fileOperationResult: FileOperationResult.FILE_MOVE_CONFLICT - }); + return TPromise.wrapError(new FileOperationError(nls.localize('fileMoveConflict', "Unable to move/copy. File already exists at destination."), FileOperationResult.FILE_MOVE_CONFLICT)); } // 2.) make sure target is deleted before we move/copy unless this is a case rename of the same file let deleteTargetPromise = TPromise.as(void 0); if (exists && !isCaseRename) { if (isEqualOrParent(sourcePath, targetPath, !isLinux /* ignorecase */)) { - return TPromise.wrapError(nls.localize('unableToMoveCopyError', "Unable to move/copy. File would replace folder it is contained in.")); // catch this corner case! + return TPromise.wrapError(new Error(nls.localize('unableToMoveCopyError', "Unable to move/copy. File would replace folder it is contained in."))); // catch this corner case! } deleteTargetPromise = this.del(uri.file(targetPath)); @@ -514,7 +505,7 @@ export class FileService implements IFileService { // 1.) resolve return pfs.stat(sourcePath).then(stat => { if (stat.isDirectory()) { - return TPromise.wrapError(nls.localize('foldersCopyError', "Folders cannot be copied into the workspace. Please select individual files to copy them.")); // for now we do not allow to import a folder into a workspace + return TPromise.wrapError(new Error(nls.localize('foldersCopyError', "Folders cannot be copied into the workspace. Please select individual files to copy them."))); // for now we do not allow to import a folder into a workspace } // 2.) copy @@ -574,10 +565,7 @@ export class FileService implements IFileService { // Return early if file is too large to load if (types.isNumber(model.size) && model.size > MAX_FILE_SIZE) { - return TPromise.wrapError({ - message: nls.localize('fileTooLargeError', "File too large to open"), - fileOperationResult: FileOperationResult.FILE_TOO_LARGE - }); + return TPromise.wrapError(new FileOperationError(nls.localize('fileTooLargeError', "File too large to open"), FileOperationResult.FILE_TOO_LARGE)); } const absolutePath = this.toAbsolutePath(model); @@ -682,10 +670,7 @@ export class FileService implements IFileService { // Find out if content length has changed if (options.etag !== etag(stat.size, options.mtime)) { - return TPromise.wrapError({ - message: nls.localize('fileModifiedError', "File Modified Since"), - fileOperationResult: FileOperationResult.FILE_MODIFIED_SINCE - }); + return TPromise.wrapError(new FileOperationError(nls.localize('fileModifiedError', "File Modified Since"), FileOperationResult.FILE_MODIFIED_SINCE)); } } @@ -694,10 +679,10 @@ export class FileService implements IFileService { // Throw if file is readonly and we are not instructed to overwrite if (readonly && !options.overwriteReadonly) { - return TPromise.wrapError({ - message: nls.localize('fileReadOnlyError', "File is Read Only"), - fileOperationResult: FileOperationResult.FILE_READ_ONLY - }); + return TPromise.wrapError(new FileOperationError( + nls.localize('fileReadOnlyError', "File is Read Only"), + FileOperationResult.FILE_READ_ONLY + )); } if (readonly) { diff --git a/src/vs/workbench/services/files/test/node/fileService.test.ts b/src/vs/workbench/services/files/test/node/fileService.test.ts index aa98674ec561981a41c37d1b842a19786d48cfdc..09778ad2701b457e55942d481f9466554033a574 100644 --- a/src/vs/workbench/services/files/test/node/fileService.test.ts +++ b/src/vs/workbench/services/files/test/node/fileService.test.ts @@ -12,7 +12,7 @@ import assert = require('assert'); import { TPromise } from 'vs/base/common/winjs.base'; import { FileService, IEncodingOverride } from 'vs/workbench/services/files/node/fileService'; -import { FileOperation, FileOperationEvent, FileChangesEvent, FileOperationResult, IFileOperationResult } from 'vs/platform/files/common/files'; +import { FileOperation, FileOperationEvent, FileChangesEvent, FileOperationResult, FileOperationError } from 'vs/platform/files/common/files'; import uri from 'vs/base/common/uri'; import uuid = require('vs/base/common/uuid'); import extfs = require('vs/base/node/extfs'); @@ -229,7 +229,7 @@ suite('FileService', () => { }); service.resolveFile(uri.file(path.join(testDir, 'index.html'))).done(source => { - return service.moveFile(source.resource, uri.file(path.join(testDir, 'binary.txt'))).then(null, (e: IFileOperationResult) => { + return service.moveFile(source.resource, uri.file(path.join(testDir, 'binary.txt'))).then(null, (e: FileOperationError) => { assert.equal(e.fileOperationResult, FileOperationResult.FILE_MOVE_CONFLICT); assert.ok(!event); @@ -603,7 +603,7 @@ suite('FileService', () => { test('resolveContent - FILE_IS_BINARY', function (done: () => void) { let resource = uri.file(path.join(testDir, 'binary.txt')); - service.resolveContent(resource, { acceptTextOnly: true }).done(null, (e: IFileOperationResult) => { + service.resolveContent(resource, { acceptTextOnly: true }).done(null, (e: FileOperationError) => { assert.equal(e.fileOperationResult, FileOperationResult.FILE_IS_BINARY); return service.resolveContent(uri.file(path.join(testDir, 'small.txt')), { acceptTextOnly: true }).then(r => { @@ -617,7 +617,7 @@ suite('FileService', () => { test('resolveContent - FILE_IS_DIRECTORY', function (done: () => void) { let resource = uri.file(path.join(testDir, 'deep')); - service.resolveContent(resource).done(null, (e: IFileOperationResult) => { + service.resolveContent(resource).done(null, (e: FileOperationError) => { assert.equal(e.fileOperationResult, FileOperationResult.FILE_IS_DIRECTORY); done(); @@ -627,7 +627,7 @@ suite('FileService', () => { test('resolveContent - FILE_NOT_FOUND', function (done: () => void) { let resource = uri.file(path.join(testDir, '404.html')); - service.resolveContent(resource).done(null, (e: IFileOperationResult) => { + service.resolveContent(resource).done(null, (e: FileOperationError) => { assert.equal(e.fileOperationResult, FileOperationResult.FILE_NOT_FOUND); done(); @@ -638,7 +638,7 @@ suite('FileService', () => { let resource = uri.file(path.join(testDir, 'index.html')); service.resolveContent(resource).done(c => { - return service.resolveContent(resource, { etag: c.etag }).then(null, (e: IFileOperationResult) => { + return service.resolveContent(resource, { etag: c.etag }).then(null, (e: FileOperationError) => { assert.equal(e.fileOperationResult, FileOperationResult.FILE_NOT_MODIFIED_SINCE); done(); @@ -652,7 +652,7 @@ suite('FileService', () => { service.resolveContent(resource).done(c => { fs.writeFileSync(resource.fsPath, 'Updates Incoming!'); - return service.updateContent(resource, c.value, { etag: c.etag, mtime: c.mtime - 1000 }).then(null, (e: IFileOperationResult) => { + return service.updateContent(resource, c.value, { etag: c.etag, mtime: c.mtime - 1000 }).then(null, (e: FileOperationError) => { assert.equal(e.fileOperationResult, FileOperationResult.FILE_MODIFIED_SINCE); done(); diff --git a/src/vs/workbench/services/keybinding/common/keybindingEditing.ts b/src/vs/workbench/services/keybinding/common/keybindingEditing.ts index c9793ddfb0148bf5ef2db63aab40bb933970bc3e..c1876d709f129545728cfc6d669abea5c62db9f8 100644 --- a/src/vs/workbench/services/keybinding/common/keybindingEditing.ts +++ b/src/vs/workbench/services/keybinding/common/keybindingEditing.ts @@ -225,7 +225,7 @@ export class KeybindingsEditingService extends Disposable implements IKeybinding // Target cannot be dirty if not writing into buffer if (this.textFileService.isDirty(this.resource)) { - return TPromise.wrapError>(localize('errorKeybindingsFileDirty', "Unable to write because the file is dirty. Please save the **Keybindings** file and try again.")); + return TPromise.wrapError>(new Error(localize('errorKeybindingsFileDirty', "Unable to write because the file is dirty. Please save the **Keybindings** file and try again."))); } return this.resolveModelReference() @@ -235,11 +235,11 @@ export class KeybindingsEditingService extends Disposable implements IKeybinding if (model.getValue()) { const parsed = this.parse(model); if (parsed.parseErrors.length) { - return TPromise.wrapError>(localize('parseErrors', "Unable to write keybindings. Please open **Keybindings file** to correct errors/warnings in the file and try again.")); + return TPromise.wrapError>(new Error(localize('parseErrors', "Unable to write keybindings. Please open **Keybindings file** to correct errors/warnings in the file and try again."))); } if (parsed.result) { if (!isArray(parsed.result)) { - return TPromise.wrapError>(localize('errorInvalidConfiguration', "Unable to write keybindings. **Keybindings file** has an object which is not of type Array. Please open the file to clean up and try again.")); + return TPromise.wrapError>(new Error(localize('errorInvalidConfiguration', "Unable to write keybindings. **Keybindings file** has an object which is not of type Array. Please open the file to clean up and try again."))); } } else { const content = EOL + '[]'; diff --git a/src/vs/workbench/services/keybinding/test/node/keybindingEditing.test.ts b/src/vs/workbench/services/keybinding/test/node/keybindingEditing.test.ts index 8c8511b59e7b22607669cd1904db1ec1046d63e2..89dcc74ef242d4f6403cf147621f1e1ce953c253 100644 --- a/src/vs/workbench/services/keybinding/test/node/keybindingEditing.test.ts +++ b/src/vs/workbench/services/keybinding/test/node/keybindingEditing.test.ts @@ -111,28 +111,28 @@ suite('Keybindings Editing', () => { fs.writeFileSync(keybindingsFile, ',,,,,,,,,,,,,,'); return testObject.editKeybinding('alt+c', aResolvedKeybindingItem({ firstPart: { keyCode: KeyCode.Escape } })) .then(() => assert.fail('Should fail with parse errors'), - error => assert.equal(error, 'Unable to write keybindings. Please open **Keybindings file** to correct errors/warnings in the file and try again.')); + error => assert.equal(error.message, 'Unable to write keybindings. Please open **Keybindings file** to correct errors/warnings in the file and try again.')); }); test('errors cases - parse errors 2', () => { fs.writeFileSync(keybindingsFile, '[{"key": }]'); return testObject.editKeybinding('alt+c', aResolvedKeybindingItem({ firstPart: { keyCode: KeyCode.Escape } })) .then(() => assert.fail('Should fail with parse errors'), - error => assert.equal(error, 'Unable to write keybindings. Please open **Keybindings file** to correct errors/warnings in the file and try again.')); + error => assert.equal(error.message, 'Unable to write keybindings. Please open **Keybindings file** to correct errors/warnings in the file and try again.')); }); test('errors cases - dirty', () => { instantiationService.stub(ITextFileService, 'isDirty', true); return testObject.editKeybinding('alt+c', aResolvedKeybindingItem({ firstPart: { keyCode: KeyCode.Escape } })) .then(() => assert.fail('Should fail with dirty error'), - error => assert.equal(error, 'Unable to write because the file is dirty. Please save the **Keybindings** file and try again.')); + error => assert.equal(error.message, 'Unable to write because the file is dirty. Please save the **Keybindings** file and try again.')); }); test('errors cases - did not find an array', () => { fs.writeFileSync(keybindingsFile, '{"key": "alt+c", "command": "hello"}'); return testObject.editKeybinding('alt+c', aResolvedKeybindingItem({ firstPart: { keyCode: KeyCode.Escape } })) .then(() => assert.fail('Should fail with dirty error'), - error => assert.equal(error, 'Unable to write keybindings. **Keybindings file** has an object which is not of type Array. Please open the file to clean up and try again.')); + error => assert.equal(error.message, 'Unable to write keybindings. **Keybindings file** has an object which is not of type Array. Please open the file to clean up and try again.')); }); test('edit a default keybinding to an empty file', () => { diff --git a/src/vs/workbench/services/textfile/common/textFileEditorModel.ts b/src/vs/workbench/services/textfile/common/textFileEditorModel.ts index d004f0414d6cffd5280292036e235f2341c46e5e..e7dd80b67559ef4889849830be02519d9cb8b2b1 100644 --- a/src/vs/workbench/services/textfile/common/textFileEditorModel.ts +++ b/src/vs/workbench/services/textfile/common/textFileEditorModel.ts @@ -25,7 +25,7 @@ import { ITextFileService, IAutoSaveConfiguration, ModelState, ITextFileEditorMo import { EncodingMode } from 'vs/workbench/common/editor'; import { BaseTextEditorModel } from 'vs/workbench/common/editor/textEditorModel'; import { IBackupFileService, BACKUP_FILE_RESOLVE_OPTIONS } from 'vs/workbench/services/backup/common/backup'; -import { IFileService, IFileStat, IFileOperationResult, FileOperationResult, IContent, CONTENT_CHANGE_EVENT_BUFFER_DELAY, FileChangesEvent, FileChangeType } from 'vs/platform/files/common/files'; +import { IFileService, IFileStat, FileOperationError, FileOperationResult, IContent, CONTENT_CHANGE_EVENT_BUFFER_DELAY, FileChangesEvent, FileChangeType } from 'vs/platform/files/common/files'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IMessageService, Severity } from 'vs/platform/message/common/message'; import { IModeService } from 'vs/editor/common/services/modeService'; @@ -331,7 +331,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil return this.loadWithContent(content); } - private handleLoadError(error: IFileOperationResult): TPromise { + private handleLoadError(error: FileOperationError): TPromise { const result = error.fileOperationResult; // Apply orphaned state based on error code @@ -699,7 +699,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil this.inErrorMode = true; // Look out for a save conflict - if ((error).fileOperationResult === FileOperationResult.FILE_MODIFIED_SINCE) { + if ((error).fileOperationResult === FileOperationResult.FILE_MODIFIED_SINCE) { this.inConflictMode = true; } diff --git a/src/vs/workbench/services/textfile/common/textFileService.ts b/src/vs/workbench/services/textfile/common/textFileService.ts index 3732c84748a5218adc368301214574f6b04c190c..26b2179a48e6f1bf7f1eca67d25c7aa271a4a72c 100644 --- a/src/vs/workbench/services/textfile/common/textFileService.ts +++ b/src/vs/workbench/services/textfile/common/textFileService.ts @@ -18,7 +18,7 @@ import { IRevertOptions, IResult, ITextFileOperationResult, ITextFileService, IR import { ConfirmResult } from 'vs/workbench/common/editor'; import { ILifecycleService, ShutdownReason } from 'vs/platform/lifecycle/common/lifecycle'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; -import { IFileService, IResolveContentOptions, IFilesConfiguration, IFileOperationResult, FileOperationResult, AutoSaveConfiguration, HotExitConfiguration } from 'vs/platform/files/common/files'; +import { IFileService, IResolveContentOptions, IFilesConfiguration, FileOperationError, FileOperationResult, AutoSaveConfiguration, HotExitConfiguration } from 'vs/platform/files/common/files'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IDisposable, dispose } from 'vs/base/common/lifecycle'; @@ -602,7 +602,7 @@ export abstract class TextFileService implements ITextFileService { }, error => { // binary model: delete the file and run the operation again - if ((error).fileOperationResult === FileOperationResult.FILE_IS_BINARY || (error).fileOperationResult === FileOperationResult.FILE_TOO_LARGE) { + if ((error).fileOperationResult === FileOperationResult.FILE_IS_BINARY || (error).fileOperationResult === FileOperationResult.FILE_TOO_LARGE) { return this.fileService.del(target).then(() => this.doSaveTextFileAs(sourceModel, resource, target)); } @@ -654,7 +654,7 @@ export abstract class TextFileService implements ITextFileService { }, error => { // FileNotFound means the file got deleted meanwhile, so still record as successful revert - if ((error).fileOperationResult === FileOperationResult.FILE_NOT_FOUND) { + if ((error).fileOperationResult === FileOperationResult.FILE_NOT_FOUND) { mapResourceToResult.get(model.getResource()).success = true; } diff --git a/src/vs/workbench/services/textfile/test/textFileEditorModel.test.ts b/src/vs/workbench/services/textfile/test/textFileEditorModel.test.ts index ee60658f08c0c05b6897fa456366b6ea0d98a579..b7a1a21e0f30c9073d84aef885da3b3c55bf47d6 100644 --- a/src/vs/workbench/services/textfile/test/textFileEditorModel.test.ts +++ b/src/vs/workbench/services/textfile/test/textFileEditorModel.test.ts @@ -14,7 +14,7 @@ import { ITextFileService, ModelState, StateChange } from 'vs/workbench/services import { workbenchInstantiationService, TestTextFileService, createFileInput, TestFileService } from 'vs/workbench/test/workbenchTestServices'; import { onError, toResource } from 'vs/base/test/common/utils'; import { TextFileEditorModelManager } from 'vs/workbench/services/textfile/common/textFileEditorModelManager'; -import { FileOperationResult, IFileOperationResult, IFileService } from 'vs/platform/files/common/files'; +import { FileOperationResult, FileOperationError, IFileService } from 'vs/platform/files/common/files'; import { IModelService } from 'vs/editor/common/services/modelService'; class ServiceAccessor { @@ -195,10 +195,7 @@ suite('Files - TextFileEditorModel', () => { model.load().done(() => { const mtime = getLastModifiedTime(model); - accessor.textFileService.setResolveTextContentErrorOnce({ - message: 'error', - fileOperationResult: FileOperationResult.FILE_NOT_MODIFIED_SINCE - }); + accessor.textFileService.setResolveTextContentErrorOnce(new FileOperationError('error', FileOperationResult.FILE_NOT_MODIFIED_SINCE)); return model.load().then((model: TextFileEditorModel) => { assert.ok(model); @@ -214,10 +211,7 @@ suite('Files - TextFileEditorModel', () => { const model: TextFileEditorModel = instantiationService.createInstance(TextFileEditorModel, toResource.call(this, '/path/index_async.txt'), 'utf8'); model.load().done(() => { - accessor.textFileService.setResolveTextContentErrorOnce({ - message: 'error', - fileOperationResult: FileOperationResult.FILE_NOT_FOUND - }); + accessor.textFileService.setResolveTextContentErrorOnce(new FileOperationError('error', FileOperationResult.FILE_NOT_FOUND)); return model.load().then((model: TextFileEditorModel) => { assert.ok(model); @@ -329,7 +323,7 @@ suite('Files - TextFileEditorModel', () => { TextFileEditorModel.setSaveParticipant({ participate: (model) => { - return TPromise.wrapError('boom'); + return TPromise.wrapError(new Error('boom')); } }); diff --git a/src/vs/workbench/services/textmodelResolver/common/textModelResolverService.ts b/src/vs/workbench/services/textmodelResolver/common/textModelResolverService.ts index f8f999792122529d1e800ed486efb2be444be90c..c7b7668b869c6e27a86a7d1e7a9a5a41ce10fcd2 100644 --- a/src/vs/workbench/services/textmodelResolver/common/textModelResolverService.ts +++ b/src/vs/workbench/services/textmodelResolver/common/textModelResolverService.ts @@ -84,7 +84,7 @@ class ResourceModelCollection extends ReferenceCollection { if (!model) { console.error(`Unable to open '${resource}' resource is not available.`); // TODO PII - return TPromise.wrapError('resource is not available'); + return TPromise.wrapError(new Error('resource is not available')); } return model; @@ -125,7 +125,7 @@ export class TextModelResolverService implements ITextModelService { const cachedModel = this.modelService.getModel(resource); if (!cachedModel) { - return TPromise.wrapError>('Cant resolve inmemory resource'); + return TPromise.wrapError>(new Error('Cant resolve inmemory resource')); } return TPromise.as(new ImmortalReference(this.instantiationService.createInstance(ResourceEditorModel, resource))); diff --git a/src/vs/workbench/services/themes/electron-browser/workbenchThemeService.ts b/src/vs/workbench/services/themes/electron-browser/workbenchThemeService.ts index 062575d13a08189a8e22f3e61ac1b09b5c2deeff..134c8cd769bc10c654db4442dfa8c03a85d11119 100644 --- a/src/vs/workbench/services/themes/electron-browser/workbenchThemeService.ts +++ b/src/vs/workbench/services/themes/electron-browser/workbenchThemeService.ts @@ -402,7 +402,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService { this.updateDynamicCSSRules(themeData); return this.applyTheme(themeData, settingsTarget); }, error => { - return TPromise.wrapError(nls.localize('error.cannotloadtheme', "Unable to load {0}: {1}", themeData.path, error.message)); + return TPromise.wrapError(new Error(nls.localize('error.cannotloadtheme', "Unable to load {0}: {1}", themeData.path, error.message))); }); } return null; @@ -734,7 +734,7 @@ function _applyIconTheme(data: IInternalIconThemeData, onApply: (theme: IInterna _applyRules(data.styleSheetContent, iconThemeRulesClassName); return onApply(data); }, error => { - return TPromise.wrapError(nls.localize('error.cannotloadicontheme', "Unable to load {0}", data.path)); + return TPromise.wrapError(new Error(nls.localize('error.cannotloadicontheme', "Unable to load {0}", data.path))); }); } diff --git a/src/vs/workbench/test/electron-browser/api/extHostApiCommands.test.ts b/src/vs/workbench/test/electron-browser/api/extHostApiCommands.test.ts index 93bf0a5b895ad56ac7be8b4545e925f8ac9ffc9f..bdc0d30f2a4822bf1ab109f6814ac74f0d2018c7 100644 --- a/src/vs/workbench/test/electron-browser/api/extHostApiCommands.test.ts +++ b/src/vs/workbench/test/electron-browser/api/extHostApiCommands.test.ts @@ -70,7 +70,7 @@ suite('ExtHostLanguageFeatureCommands', function () { _serviceBrand: undefined, executeCommand(id, args): any { if (!CommandsRegistry.getCommands()[id]) { - return TPromise.wrapError(id + ' NOT known'); + return TPromise.wrapError(new Error(id + ' NOT known')); } let { handler } = CommandsRegistry.getCommands()[id]; return TPromise.as(instantiationService.invokeFunction(handler, args)); diff --git a/src/vs/workbench/test/electron-browser/api/extHostConfiguration.test.ts b/src/vs/workbench/test/electron-browser/api/extHostConfiguration.test.ts index 9a8a3bb9c335de73a718d226e13595069935fd0a..4a4fb81723824d89470fa2159162f6f6f0a05d4b 100644 --- a/src/vs/workbench/test/electron-browser/api/extHostConfiguration.test.ts +++ b/src/vs/workbench/test/electron-browser/api/extHostConfiguration.test.ts @@ -11,7 +11,7 @@ import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace'; import { ExtHostConfiguration } from 'vs/workbench/api/node/extHostConfiguration'; import { MainThreadConfigurationShape } from 'vs/workbench/api/node/extHost.protocol'; import { TPromise } from 'vs/base/common/winjs.base'; -import { ConfigurationTarget, ConfigurationEditingErrorCode, IConfigurationEditingError } from 'vs/workbench/services/configuration/common/configurationEditing'; +import { ConfigurationTarget, ConfigurationEditingErrorCode, ConfigurationEditingError } from 'vs/workbench/services/configuration/common/configurationEditing'; import { ConfigurationModel } from 'vs/platform/configuration/common/configuration'; import { TestThreadService } from './testThreadService'; @@ -213,7 +213,7 @@ suite('ExtHostConfiguration', function () { const shape = new class extends MainThreadConfigurationShape { $updateConfigurationOption(target: ConfigurationTarget, key: string, value: any): TPromise { - return TPromise.wrapError({ code: ConfigurationEditingErrorCode.ERROR_UNKNOWN_KEY, message: 'Unknown Key' }); // something !== OK + return TPromise.wrapError(new ConfigurationEditingError('Unknown Key', ConfigurationEditingErrorCode.ERROR_UNKNOWN_KEY)); // something !== OK } }; diff --git a/src/vs/workbench/test/electron-browser/api/extHostDocumentSaveParticipant.test.ts b/src/vs/workbench/test/electron-browser/api/extHostDocumentSaveParticipant.test.ts index 9337d6376233cbc0eae32f6ed4c39f81bccfe404..9445d6bcaf251982ffa91eee641234a0ec0345fc 100644 --- a/src/vs/workbench/test/electron-browser/api/extHostDocumentSaveParticipant.test.ts +++ b/src/vs/workbench/test/electron-browser/api/extHostDocumentSaveParticipant.test.ts @@ -235,7 +235,7 @@ suite('ExtHostDocumentSaveParticipant', () => { const participant = new ExtHostDocumentSaveParticipant(documents, workspace); let sub1 = participant.onWillSaveTextDocumentEvent(function (e) { - e.waitUntil(TPromise.wrapError('dddd')); + e.waitUntil(TPromise.wrapError(new Error('dddd'))); }); let event: vscode.TextDocumentWillSaveEvent; diff --git a/src/vs/workbench/test/workbenchTestServices.ts b/src/vs/workbench/test/workbenchTestServices.ts index 0a347d97917aa6a20a3a9a3fe47e000521e3cdca..0f6a48998aa8e5586de8660c46a59fb62afbeb12 100644 --- a/src/vs/workbench/test/workbenchTestServices.ts +++ b/src/vs/workbench/test/workbenchTestServices.ts @@ -34,7 +34,7 @@ import { ServiceCollection } from 'vs/platform/instantiation/common/serviceColle import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService'; import { IEditorGroupService, GroupArrangement, GroupOrientation, ITabOptions, IMoveOptions } from 'vs/workbench/services/group/common/groupService'; import { TextFileService } from 'vs/workbench/services/textfile/common/textFileService'; -import { FileOperationEvent, IFileService, IResolveContentOptions, IFileOperationResult, IFileStat, IImportResult, FileChangesEvent, IResolveFileOptions, IContent, IUpdateContentOptions, IStreamContent } from 'vs/platform/files/common/files'; +import { FileOperationEvent, IFileService, IResolveContentOptions, FileOperationError, IFileStat, IImportResult, FileChangesEvent, IResolveFileOptions, IContent, IUpdateContentOptions, IStreamContent } from 'vs/platform/files/common/files'; import { IModelService } from 'vs/editor/common/services/modelService'; import { ModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl'; import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl'; @@ -143,7 +143,7 @@ export class TestTextFileService extends TextFileService { private promptPath: string; private confirmResult: ConfirmResult; - private resolveTextContentError: IFileOperationResult; + private resolveTextContentError: FileOperationError; constructor( @ILifecycleService lifecycleService: ILifecycleService, @@ -170,7 +170,7 @@ export class TestTextFileService extends TextFileService { this.confirmResult = result; } - public setResolveTextContentErrorOnce(error: IFileOperationResult): void { + public setResolveTextContentErrorOnce(error: FileOperationError): void { this.resolveTextContentError = error; }