Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
chore(error): throwing strings (#3436)
Browse files Browse the repository at this point in the history
- fix throw string to throw new error
- check typeof error is string to create a new error
  • Loading branch information
cnishina authored Aug 4, 2016
1 parent 79c75eb commit 9182d58
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,26 @@ export function runFilenameOrFn_(
if (filenameOrFn &&
!(typeof filenameOrFn === 'string' ||
typeof filenameOrFn === 'function')) {
throw 'filenameOrFn must be a string or function';
throw new Error('filenameOrFn must be a string or function');
}

if (typeof filenameOrFn === 'string') {
filenameOrFn = require(resolve(configDir, filenameOrFn));
}
if (typeof filenameOrFn === 'function') {
let results = when(filenameOrFn.apply(null, args), null, (err) => {
if (err.stack) {
err.stack = exports.filterStackTrace(err.stack);
}
throw err;
});
let results =
when(filenameOrFn.apply(null, args), null, (err: string | Error) => {
if (typeof err === 'string') {
err = new Error(err);
} else {
err = err as Error;
if (err.stack) {
err.stack = new Error().stack;
}
}
err.stack = exports.filterStackTrace(err.stack);
throw err;
});
resolvePromise(results);
} else {
resolvePromise(undefined);
Expand Down

0 comments on commit 9182d58

Please sign in to comment.