From 116b3f45614c7a7ca7e2899c72d6218bdfca0ccf Mon Sep 17 00:00:00 2001 From: Thomas Drosdzoll Date: Sun, 24 Mar 2019 13:49:02 +0100 Subject: [PATCH] Promise.reject uses Error instead of strings Signed-off-by: Thomas Drosdzoll added new to Error instation --- packages/bunyan/src/node/bunyan-logger-server.ts | 2 +- packages/core/src/browser/dialogs.ts | 2 +- packages/core/src/browser/opener-service.ts | 2 +- packages/core/src/browser/shell/split-panels.ts | 4 ++-- packages/core/src/common/menu.ts | 2 +- .../src/common/messaging/proxy-factory.spec.ts | 2 +- packages/core/src/common/resource.ts | 2 +- .../src/node/plugin-vscode-resolver.ts | 4 ++-- packages/plugin-ext/src/api/async-util.ts | 2 +- .../src/hosted/node/hosted-instance-manager.ts | 2 +- .../src/main/browser/workspace-main.ts | 2 +- .../src/main/node/plugin-github-resolver.ts | 6 +++--- .../src/main/node/plugin-http-resolver.ts | 2 +- .../plugin-ext/src/plugin/command-registry.ts | 2 +- packages/plugin-ext/src/plugin/plugin-context.ts | 2 +- packages/task/src/node/task-server.slow-spec.ts | 16 ++++++++-------- packages/task/src/node/task-server.ts | 2 +- .../terminal-backend-contribution.slow-spec.ts | 2 +- 18 files changed, 29 insertions(+), 29 deletions(-) diff --git a/packages/bunyan/src/node/bunyan-logger-server.ts b/packages/bunyan/src/node/bunyan-logger-server.ts index 7631fee637a5a..c0eee1a1d2782 100644 --- a/packages/bunyan/src/node/bunyan-logger-server.ts +++ b/packages/bunyan/src/node/bunyan-logger-server.ts @@ -68,7 +68,7 @@ export class BunyanLoggerServer implements ILoggerServer { * documentation. */ child(name: string): Promise { if (name.length === 0) { - return Promise.reject("Can't create a logger with an empty name."); + return Promise.reject(new Error("Can't create a logger with an empty name.")); } if (this.loggers.has(name)) { diff --git a/packages/core/src/browser/dialogs.ts b/packages/core/src/browser/dialogs.ts index a8ad83b270e59..73ed510271999 100644 --- a/packages/core/src/browser/dialogs.ts +++ b/packages/core/src/browser/dialogs.ts @@ -168,7 +168,7 @@ export abstract class AbstractDialog extends BaseWidget { open(): Promise { if (this.resolve) { - return Promise.reject('The dialog is already opened.'); + return Promise.reject(new Error('The dialog is already opened.')); } this.activeElement = window.document.activeElement as HTMLElement; return new Promise((resolve, reject) => { diff --git a/packages/core/src/browser/opener-service.ts b/packages/core/src/browser/opener-service.ts index d3ef9325f365f..5739b83870093 100644 --- a/packages/core/src/browser/opener-service.ts +++ b/packages/core/src/browser/opener-service.ts @@ -95,7 +95,7 @@ export class DefaultOpenerService implements OpenerService { if (handlers.length >= 1) { return handlers[0]; } - return Promise.reject(`There is no opener for ${uri}.`); + return Promise.reject(new Error(`There is no opener for ${uri}.`)); } async getOpeners(uri?: URI, options?: OpenerOptions): Promise { diff --git a/packages/core/src/browser/shell/split-panels.ts b/packages/core/src/browser/shell/split-panels.ts index 55ad655d6e73d..bce4c6b3c55f9 100644 --- a/packages/core/src/browser/shell/split-panels.ts +++ b/packages/core/src/browser/shell/split-panels.ts @@ -52,11 +52,11 @@ export class SplitPositionHandler { */ setSidePanelSize(sidePanel: Widget, targetSize: number, options: SplitPositionOptions): Promise { if (targetSize < 0) { - return Promise.reject('Cannot resize to negative value.'); + return Promise.reject(new Error('Cannot resize to negative value.')); } const parent = sidePanel.parent; if (!(parent instanceof SplitPanel)) { - return Promise.reject('Widget must be contained in a SplitPanel.'); + return Promise.reject(new Error('Widget must be contained in a SplitPanel.')); } let index = parent.widgets.indexOf(sidePanel); if (index > 0 && (options.side === 'right' || options.side === 'bottom')) { diff --git a/packages/core/src/common/menu.ts b/packages/core/src/common/menu.ts index b33907ab2fb7a..752cd0f058ea5 100644 --- a/packages/core/src/common/menu.ts +++ b/packages/core/src/common/menu.ts @@ -142,7 +142,7 @@ export class MenuModelRegistry { return sub; } if (sub) { - throw Error(`'${menuId}' is not a menu group.`); + throw new Error(`'${menuId}' is not a menu group.`); } const newSub = new CompositeMenuNode(menuId); current.addNode(newSub); diff --git a/packages/core/src/common/messaging/proxy-factory.spec.ts b/packages/core/src/common/messaging/proxy-factory.spec.ts index 2b7f8cd05cd26..924b797da2bb9 100644 --- a/packages/core/src/common/messaging/proxy-factory.spec.ts +++ b/packages/core/src/common/messaging/proxy-factory.spec.ts @@ -42,7 +42,7 @@ class TestServer { } fails2(arg: string, otherArg: string): Promise { - return Promise.reject('fails2 failed'); + return Promise.reject(new Error('fails2 failed')); } } diff --git a/packages/core/src/common/resource.ts b/packages/core/src/common/resource.ts index e2506cb27b431..e095886221923 100644 --- a/packages/core/src/common/resource.ts +++ b/packages/core/src/common/resource.ts @@ -112,7 +112,7 @@ export class DefaultResourceProvider { // no-op } } - return Promise.reject(`A resource provider for '${uri.toString()}' is not registered.`); + return Promise.reject(new Error(`A resource provider for '${uri.toString()}' is not registered.`)); } } diff --git a/packages/plugin-ext-vscode/src/node/plugin-vscode-resolver.ts b/packages/plugin-ext-vscode/src/node/plugin-vscode-resolver.ts index 08bd9caf904e7..40a2a0a70bea2 100644 --- a/packages/plugin-ext-vscode/src/node/plugin-vscode-resolver.ts +++ b/packages/plugin-ext-vscode/src/node/plugin-vscode-resolver.ts @@ -57,7 +57,7 @@ export class VsCodePluginDeployerResolver implements PluginDeployerResolver { const extracted = /^vscode:extension\/(.*)/gm.exec(pluginResolverContext.getOriginId()); if (!extracted || extracted === null) { - reject('Invalid extension' + pluginResolverContext.getOriginId()); + reject(new Error('Invalid extension' + pluginResolverContext.getOriginId())); return; } const extensionName = extracted[1]; @@ -84,7 +84,7 @@ export class VsCodePluginDeployerResolver implements PluginDeployerResolver { } else if (response.statusCode === 200) { const extension = body.results[0].extensions[0]; if (!extension) { - reject('No extension'); + reject(new Error('No extension')); } let asset; if (wantedExtensionVersion !== undefined) { diff --git a/packages/plugin-ext/src/api/async-util.ts b/packages/plugin-ext/src/api/async-util.ts index a048e915afe63..48e80583ad96d 100644 --- a/packages/plugin-ext/src/api/async-util.ts +++ b/packages/plugin-ext/src/api/async-util.ts @@ -18,7 +18,7 @@ import { Deferred } from '@theia/core/lib/common/promise-util'; export function hookCancellationToken(token: CancellationToken, promise: Promise): PromiseLike { return new Promise((resolve, reject) => { - const sub = token.onCancellationRequested(() => reject('This promise is cancelled')); + const sub = token.onCancellationRequested(() => reject(new Error('This promise is cancelled'))); promise.then(value => { sub.dispose(); resolve(value); diff --git a/packages/plugin-ext/src/hosted/node/hosted-instance-manager.ts b/packages/plugin-ext/src/hosted/node/hosted-instance-manager.ts index 9de9f9f3148f4..c30e5e39322c1 100644 --- a/packages/plugin-ext/src/hosted/node/hosted-instance-manager.ts +++ b/packages/plugin-ext/src/hosted/node/hosted-instance-manager.ts @@ -313,7 +313,7 @@ export abstract class AbstractHostedInstanceManager implements HostedInstanceMan if (!started) { this.terminate(); this.isPluginRunnig = false; - reject('Timeout.'); + reject(new Error('Timeout.')); } }, HOSTED_INSTANCE_START_TIMEOUT_MS); }); diff --git a/packages/plugin-ext/src/main/browser/workspace-main.ts b/packages/plugin-ext/src/main/browser/workspace-main.ts index bef498bb472e6..7d149b4bd4a4e 100644 --- a/packages/plugin-ext/src/main/browser/workspace-main.ts +++ b/packages/plugin-ext/src/main/browser/workspace-main.ts @@ -293,7 +293,7 @@ export class TextContentResource implements Resource { } } - return Promise.reject(`Unable to get content for '${this.uri.toString()}'`); + return Promise.reject(new Error(`Unable to get content for '${this.uri.toString()}'`)); } dispose() { diff --git a/packages/plugin-ext/src/main/node/plugin-github-resolver.ts b/packages/plugin-ext/src/main/node/plugin-github-resolver.ts index 86308998220f2..4a4a7e47f8360 100644 --- a/packages/plugin-ext/src/main/node/plugin-github-resolver.ts +++ b/packages/plugin-ext/src/main/node/plugin-github-resolver.ts @@ -53,7 +53,7 @@ export class GithubPluginDeployerResolver implements PluginDeployerResolver { const extracted = /^github:(.*)\/(.*)\/(.*)$/gm.exec(pluginResolverContext.getOriginId()); if (!extracted || extracted === null || extracted.length !== 4) { - reject('Invalid extension' + pluginResolverContext.getOriginId()); + reject(new Error('Invalid extension' + pluginResolverContext.getOriginId())); return; } @@ -87,14 +87,14 @@ export class GithubPluginDeployerResolver implements PluginDeployerResolver { if (response.statusCode === 302) { const redirectLocation = response.headers.location; if (!redirectLocation) { - reject('Invalid github link with latest not being found'); + reject(new Error('Invalid github link with latest not being found')); return; } // parse redirect link const taggedValueArray = /^https:\/\/.*tag\/(.*)/gm.exec(redirectLocation); if (!taggedValueArray || taggedValueArray.length !== 2) { - reject('The redirect link for latest is invalid ' + redirectLocation); + reject(new Error('The redirect link for latest is invalid ' + redirectLocation)); return; } diff --git a/packages/plugin-ext/src/main/node/plugin-http-resolver.ts b/packages/plugin-ext/src/main/node/plugin-http-resolver.ts index 227ebfbaa1d8f..4fe923ef3560e 100644 --- a/packages/plugin-ext/src/main/node/plugin-http-resolver.ts +++ b/packages/plugin-ext/src/main/node/plugin-http-resolver.ts @@ -52,7 +52,7 @@ export class HttpPluginDeployerResolver implements PluginDeployerResolver { const urlPath = pluginResolverContext.getOriginId(); const link = url.parse(urlPath); if (!link.pathname) { - reject('invalid link URI' + urlPath); + reject(new Error('invalid link URI' + urlPath)); return; } diff --git a/packages/plugin-ext/src/plugin/command-registry.ts b/packages/plugin-ext/src/plugin/command-registry.ts index 2ef2b2428687f..8467f4883e2bb 100644 --- a/packages/plugin-ext/src/plugin/command-registry.ts +++ b/packages/plugin-ext/src/plugin/command-registry.ts @@ -75,7 +75,7 @@ export class CommandRegistryImpl implements CommandRegistryExt { if (this.handlers.has(id)) { return this.executeLocalCommand(id, ...args); } else { - return Promise.reject(`Command: ${id} does not exist.`); + return Promise.reject(new Error(`Command: ${id} does not exist.`)); } } diff --git a/packages/plugin-ext/src/plugin/plugin-context.ts b/packages/plugin-ext/src/plugin/plugin-context.ts index 438dd276d2278..bed7853400fd9 100644 --- a/packages/plugin-ext/src/plugin/plugin-context.ts +++ b/packages/plugin-ext/src/plugin/plugin-context.ts @@ -396,7 +396,7 @@ export function createAPIFactory( uri = await documents.createDocumentData(options); } else { - return Promise.reject('illegal argument - uriOrFileNameOrOptions'); + return Promise.reject(new Error('illegal argument - uriOrFileNameOrOptions')); } const data = await documents.openDocument(uri); diff --git a/packages/task/src/node/task-server.slow-spec.ts b/packages/task/src/node/task-server.slow-spec.ts index b2dd0caf5dc27..054ce333bfbf4 100644 --- a/packages/task/src/node/task-server.slow-spec.ts +++ b/packages/task/src/node/task-server.slow-spec.ts @@ -87,14 +87,14 @@ describe('Task server / back-end', function () { await new Promise((resolve, reject) => { const channel = new TestWebSocketChannel({ server, path: `${terminalsPath}/${terminalId}` }); channel.onError(reject); - channel.onClose((code, reason) => reject(`channel is closed with '${code}' code and '${reason}' reason`)); + channel.onClose((code, reason) => reject(new Error(`channel is closed with '${code}' code and '${reason}' reason`))); channel.onMessage(msg => { // check output of task on terminal is what we expect const expected = `tasking... ${someString}`; if (msg.toString().indexOf(expected) !== -1) { resolve(); } else { - reject(`expected sub-string not found in terminal output. Expected: "${expected}" vs Actual: "${msg.toString()}"`); + reject(new Error(`expected sub-string not found in terminal output. Expected: "${expected}" vs Actual: "${msg.toString()}"`)); } channel.close(); }); @@ -114,7 +114,7 @@ describe('Task server / back-end', function () { if (taskInfo.terminalId === undefined) { resolve(); } else { - reject(`terminal id was expected to be undefined, actual: ${taskInfo.terminalId}`); + reject(new Error(`terminal id was expected to be undefined, actual: ${taskInfo.terminalId}`)); } toDispose.dispose(); } @@ -272,14 +272,14 @@ describe('Task server / back-end', function () { if (runningTasksAll.length === 6) { resolve(); } else { - reject(`Error: unexpected total number of running tasks for all contexts: expected: 6, actual: ${runningTasksCtx1.length}`); + reject(new Error(`Error: unexpected total number of running tasks for all contexts: expected: 6, actual: ${runningTasksCtx1.length}`)); } } else { - reject(`Error: unexpected number of running tasks for context 2: expected: 2, actual: ${runningTasksCtx1.length}`); + reject(new Error(`Error: unexpected number of running tasks for context 2: expected: 2, actual: ${runningTasksCtx1.length}`)); } } else { - reject(`Error: unexpected number of running tasks for context 1: expected: 4, actual: ${runningTasksCtx1.length}`); + reject(new Error(`Error: unexpected number of running tasks for context 1: expected: 4, actual: ${runningTasksCtx1.length}`)); } }); @@ -320,11 +320,11 @@ describe('Task server / back-end', function () { if (numRunningTasksAfterKilled.length === 0) { resolve(); } else { - reject(`Error: remaining running tasks, after all killed: expected: 0, actual: ${numRunningTasksAfterKilled.length}`); + reject(new Error(`Error: remaining running tasks, after all killed: expected: 0, actual: ${numRunningTasksAfterKilled.length}`)); } } else { - reject(`Error: unexpected number of running tasks: expected: ${numTasks}, actual: ${numRunningTasksAfterCreated.length}`); + reject(new Error(`Error: unexpected number of running tasks: expected: ${numTasks}, actual: ${numRunningTasksAfterCreated.length}`)); } }); diff --git a/packages/task/src/node/task-server.ts b/packages/task/src/node/task-server.ts index 13abfe82ae29f..6f615b21c8302 100644 --- a/packages/task/src/node/task-server.ts +++ b/packages/task/src/node/task-server.ts @@ -95,7 +95,7 @@ export class TaskServerImpl implements TaskServer { return taskToKill.kill(); } else { this.logger.info(`Could not find task to kill, task id ${id}. Already terminated?`); - return Promise.reject(`Could not find task to kill, task id ${id}. Already terminated?`); + return Promise.reject(new Error(`Could not find task to kill, task id ${id}. Already terminated?`)); } } diff --git a/packages/terminal/src/node/terminal-backend-contribution.slow-spec.ts b/packages/terminal/src/node/terminal-backend-contribution.slow-spec.ts index 82e230dfd00fc..064f1b828db37 100644 --- a/packages/terminal/src/node/terminal-backend-contribution.slow-spec.ts +++ b/packages/terminal/src/node/terminal-backend-contribution.slow-spec.ts @@ -47,7 +47,7 @@ describe('Terminal Backend Contribution', function () { await new Promise((resolve, reject) => { const channel = new TestWebSocketChannel({ server, path: `${terminalsPath}/${terminalId}` }); channel.onError(reject); - channel.onClose((code, reason) => reject(`channel is closed with '${code}' code and '${reason}' reason`)); + channel.onClose((code, reason) => reject(new Error(`channel is closed with '${code}' code and '${reason}' reason`))); channel.onOpen(() => { resolve(); channel.close();