Skip to content

Commit

Permalink
fix: coerce unknown thrown objects into errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Sep 17, 2021
1 parent bbbf2fe commit 38b9e22
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/cli/bin/execute.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NullaryFn } from 'type-core';
import { ensure } from 'errorish';
import { stringifyError } from '../../helpers/stringify';
import { create, log } from '../../tasks';
import { Task } from '../../definitions';
Expand Down Expand Up @@ -28,7 +29,7 @@ export async function execute(task: NullaryFn<Task>): Promise<void> {

await promise;
} catch (err) {
await run(null, log('error', stringifyError(err)));
await run(null, log('error', stringifyError(ensure(err))));
return process.exit(1);
}
}
3 changes: 2 additions & 1 deletion src/tasks/exception/catches.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Empty } from 'type-core';
import { shallow } from 'merge-strategies';
import { ensure } from 'errorish';
import { into } from 'pipettes';
import { Task, Context, LogLevel } from '../../definitions';
import { stringifyError } from '../../helpers/stringify';
Expand Down Expand Up @@ -36,7 +37,7 @@ export function catches(
await into(
series(
log('trace', err),
log(opts.level, stringifyError(err)),
log(opts.level, stringifyError(ensure(err))),
alternate
),
(task) => run(ctx, task)
Expand Down
3 changes: 2 additions & 1 deletion src/tasks/exception/finalize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Empty, Dictionary } from 'type-core';
import { ensure } from 'errorish';
import { Task } from '../../definitions';
import { run } from '../../utils/run';
import { flatten } from '../../helpers/flatten';
Expand Down Expand Up @@ -30,7 +31,7 @@ export function finalize(
try {
await run(ctx, item);
} catch (err) {
errors.push(err);
errors.push(ensure(err));
}
})
: null;
Expand Down
3 changes: 2 additions & 1 deletion src/tasks/stdio/prompt.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Empty, TypeGuard, UnaryFn, VariadicFn } from 'type-core';
import { shallow } from 'merge-strategies';
import { createInterface } from 'readline';
import { ensure } from 'errorish';
import { Context, Task } from '../../definitions';
import { getBadge } from '../../helpers/badges';
import { addPrefix } from '../../helpers/prefix';
Expand Down Expand Up @@ -107,7 +108,7 @@ export function prompt(options: PromptOptions | Empty, task: Task): Task.Async {
try {
valid = opts.validate(response);
} catch (err) {
error = [err];
error = [ensure(err)];
}

if (valid && !error) {
Expand Down

0 comments on commit 38b9e22

Please sign in to comment.