Skip to content

Commit

Permalink
feat: log all errors w/ trace level
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Apr 6, 2021
1 parent 1d26381 commit 96425e0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/cli/bin/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { styleString } from '../../helpers/style-string';
import { resolveProject } from '../../helpers/resolve-project';
import { stringifyArgvCommands } from '../../helpers/stringify';
import { print, raises, series, create, context, log } from '../../tasks';
import { Task, LogLevel, CLI } from '../../definitions';
import { Task, LogLevel, CLI, Context } from '../../definitions';
import { constants } from '../../constants';

export function main(argv: string[], options: Required<CLI.Options>): Task {
Expand Down Expand Up @@ -175,6 +175,16 @@ export function main(argv: string[], options: Required<CLI.Options>): Task {
)
);
}),
(task) => {
return async (ctx: Context): Promise<void> => {
try {
await task(ctx);
} catch (err) {
into(ctx, log('trace', err));
throw err;
}
};
},
context.bind(null, {
level: opts.level,
prefix: opts.prefix,
Expand Down
1 change: 1 addition & 0 deletions src/tasks/exception/catches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function catches(
} catch (err) {
if (await isCancelled(ctx)) return;

into(ctx, log('trace', err));
into(ctx, log(opts.level, stringifyError(err)));
if (alternate) await run(alternate, ctx);
}
Expand Down
9 changes: 8 additions & 1 deletion src/tasks/exception/finalize.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { into } from 'pipettes';
import { Task, Context } from '../../definitions';
import { isCancelled } from '../../utils/is-cancelled';
import { run } from '../../utils/run';
import { log } from '../stdio/log';

/**
* Always executes a `final` task after another.
Expand All @@ -27,6 +29,11 @@ export function finalize(task: Task, final?: Task | null): Task.Async {
}

if (!errors.length || (await isCancelled(ctx))) return;
throw errors.pop();

const err = errors.pop();
while (errors.length > 0) {
into(ctx, log('trace', errors.shift()));
}
throw err;
};
}
1 change: 1 addition & 0 deletions src/tasks/process/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export function exec(
const cmd = file || fullArgs.filter((arg) => arg[0] !== '-')[0];
message += !cmd || cmd.includes(path.sep) ? '' : `: ${file}`;

into(ctx, log('trace', err));
throw Error(message);
});
};
Expand Down

0 comments on commit 96425e0

Please sign in to comment.