Skip to content

Commit dbe0f89

Browse files
committed
Always reject Promises with Error instances
1 parent d0a6cc2 commit dbe0f89

63 files changed

Lines changed: 207 additions & 236 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/vs/base/node/processes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export abstract class AbstractProcess<TProgressData> {
168168

169169
public start(): PPromise<SuccessData, TProgressData> {
170170
if (Platform.isWindows && ((this.options && this.options.cwd && TPath.isUNC(this.options.cwd)) || !this.options && !this.options.cwd && TPath.isUNC(process.cwd()))) {
171-
return Promise.wrapError(nls.localize('TaskRunner.UNC', 'Can\'t execute a shell command on an UNC drive.'));
171+
return Promise.wrapError(new Error(nls.localize('TaskRunner.UNC', 'Can\'t execute a shell command on an UNC drive.')));
172172
}
173173
return this.useExec().then((useExec) => {
174174
let cc: TValueCallback<SuccessData>;

src/vs/base/parts/ipc/common/ipc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ export class IPCServer implements IChannelServer, IRoutingChannelClient, IDispos
384384
const id = router.route(command, arg);
385385

386386
if (!id) {
387-
return TPromise.wrapError('Client id should be provided');
387+
return TPromise.wrapError(new Error('Client id should be provided'));
388388
}
389389

390390
return this.getClient(id).then(client => client.getChannel(channelName).call(command, arg));

src/vs/base/parts/ipc/node/ipc.cp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class Client implements IChannelClient, IDisposable {
9595

9696
protected request(channelName: string, name: string, arg: any): Promise {
9797
if (!this.disposeDelayer) {
98-
return Promise.wrapError('disposed');
98+
return Promise.wrapError(new Error('disposed'));
9999
}
100100

101101
this.disposeDelayer.cancel();

src/vs/base/test/common/async.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ suite('Async', () => {
495495

496496
let f1 = () => TPromise.as(true).then(() => res.push(1));
497497
let f2 = () => TPromise.timeout(10).then(() => res.push(2));
498-
let f3 = () => TPromise.as(true).then(() => TPromise.wrapError('error'));
498+
let f3 = () => TPromise.as(true).then(() => TPromise.wrapError(new Error('error')));
499499
let f4 = () => TPromise.timeout(20).then(() => res.push(4));
500500
let f5 = () => TPromise.timeout(0).then(() => res.push(5));
501501

src/vs/base/test/common/cache.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ suite('Cache', () => {
2323

2424
test('simple error', () => {
2525
let counter = 0;
26-
const cache = new Cache(() => TPromise.wrapError(counter++));
26+
const cache = new Cache(() => TPromise.wrapError(new Error(String(counter++))));
2727

2828
return cache.get()
29-
.then(() => assert.fail(), err => assert.equal(err, 0))
29+
.then(() => assert.fail(), err => assert.equal(err.message, 0))
3030
.then(() => cache.get())
31-
.then(() => assert.fail(), err => assert.equal(err, 0));
31+
.then(() => assert.fail(), err => assert.equal(err.message, 0));
3232
});
3333

3434
test('should retry cancellations', () => {

src/vs/code/electron-main/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function setupIPC(accessor: ServicesAccessor): TPromise<Server> {
109109
const msg = 'Running extension tests from the command line is currently only supported if no other instance of Code is running.';
110110
console.error(msg);
111111
client.dispose();
112-
return TPromise.wrapError<Server>(msg);
112+
return TPromise.wrapError<Server>(new Error(msg));
113113
}
114114

115115
logService.log('Sending env to running instance...');
@@ -120,7 +120,7 @@ function setupIPC(accessor: ServicesAccessor): TPromise<Server> {
120120
return allowSetForegroundWindow(service)
121121
.then(() => service.start(environmentService.args, process.env))
122122
.then(() => client.dispose())
123-
.then(() => TPromise.wrapError<Server>('Sent env to running instance. Terminating...'));
123+
.then(() => TPromise.wrapError<Server>(new Error('Sent env to running instance. Terminating...')));
124124
},
125125
err => {
126126
if (!retry || platform.isWindows || err.code !== 'ECONNREFUSED') {

src/vs/code/node/cliProcessMain.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class Main {
116116
const [extension] = result.firstPage;
117117

118118
if (!extension) {
119-
return TPromise.wrapError(`${notFound(id)}\n${useId}`);
119+
return TPromise.wrapError(new Error(`${notFound(id)}\n${useId}`));
120120
}
121121

122122
console.log(localize('foundExtension', "Found '{0}' in the marketplace.", id));
@@ -137,7 +137,7 @@ class Main {
137137
const [extension] = installed.filter(e => getId(e.manifest) === id);
138138

139139
if (!extension) {
140-
return TPromise.wrapError(`${notInstalled(id)}\n${useId}`);
140+
return TPromise.wrapError(new Error(`${notInstalled(id)}\n${useId}`));
141141
}
142142

143143
console.log(localize('uninstalling', "Uninstalling {0}...", id));

src/vs/editor/common/services/bulkEdit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ export function createBulkEdit(textModelResolverService: ITextModelService, edit
338338

339339
let concurrentEdits = getConcurrentEdits();
340340
if (concurrentEdits) {
341-
return TPromise.wrapError<ISelection>(concurrentEdits);
341+
return TPromise.wrapError<ISelection>(new Error(concurrentEdits));
342342
}
343343

344344
let uri: URI;

src/vs/editor/contrib/links/common/links.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class Link implements ILink {
3838
try {
3939
return TPromise.as(URI.parse(this._link.url));
4040
} catch (e) {
41-
return TPromise.wrapError<URI>('invalid');
41+
return TPromise.wrapError<URI>(new Error('invalid'));
4242
}
4343
}
4444

@@ -50,11 +50,11 @@ export class Link implements ILink {
5050
return this.resolve();
5151
}
5252

53-
return TPromise.wrapError<URI>('missing');
53+
return TPromise.wrapError<URI>(new Error('missing'));
5454
});
5555
}
5656

57-
return TPromise.wrapError<URI>('missing');
57+
return TPromise.wrapError<URI>(new Error('missing'));
5858
}
5959
}
6060

src/vs/editor/contrib/rename/browser/rename.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export function rename(model: IReadOnlyModel, position: Position, newName: strin
5454
return undefined;
5555
}, err => {
5656
onUnexpectedExternalError(err);
57-
return TPromise.wrapError<WorkspaceEdit>('provider failed');
57+
return TPromise.wrapError<WorkspaceEdit>(new Error('provider failed'));
5858
});
5959
}
6060
return undefined;
@@ -198,7 +198,7 @@ class RenameController implements IEditorContribution {
198198

199199
return rename(this.editor.getModel(), this.editor.getPosition(), newName).then(result => {
200200
if (result.rejectReason) {
201-
return TPromise.wrapError<BulkEdit>(result.rejectReason);
201+
return TPromise.wrapError<BulkEdit>(new Error(result.rejectReason));
202202
}
203203
edit.add(result.edits);
204204
return edit;

0 commit comments

Comments
 (0)