Skip to content

Commit

Permalink
Promise.reject uses an Error instead of a string
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Drosdzoll <thomas.drosdzoll@gmx.net>

Promise.reject uses Error instead of strings

Signed-off-by: Thomas Drosdzoll <thomas.drosdzoll@gmx.net>
  • Loading branch information
theBadT committed Mar 25, 2019
1 parent 89c3e75 commit 49d06b9
Show file tree
Hide file tree
Showing 17 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion packages/bunyan/src/node/bunyan-logger-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class BunyanLoggerServer implements ILoggerServer {
* documentation. */
child(name: string): Promise<void> {
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)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/browser/dialogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export abstract class AbstractDialog<T> extends BaseWidget {

open(): Promise<T | undefined> {
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<T | undefined>((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/browser/opener-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<OpenHandler[]> {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/browser/shell/split-panels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ export class SplitPositionHandler {
*/
setSidePanelSize(sidePanel: Widget, targetSize: number, options: SplitPositionOptions): Promise<number> {
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')) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/common/messaging/proxy-factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class TestServer {
}

fails2(arg: string, otherArg: string): Promise<string> {
return Promise.reject('fails2 failed');
return Promise.reject(new Error('fails2 failed'));
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/common/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`));
}

}
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-ext-vscode/src/node/plugin-vscode-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/api/async-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Deferred } from '@theia/core/lib/common/promise-util';

export function hookCancellationToken<T>(token: CancellationToken, promise: Promise<T>): PromiseLike<T> {
return new Promise<T>((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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/main/browser/workspace-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-ext/src/main/node/plugin-github-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/main/node/plugin-http-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/plugin/command-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`));
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions packages/task/src/node/task-server.slow-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand All @@ -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();
}
Expand Down Expand Up @@ -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}`));
}
});

Expand Down Expand Up @@ -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}`));
}
});

Expand Down
2 changes: 1 addition & 1 deletion packages/task/src/node/task-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?`));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 49d06b9

Please sign in to comment.