Skip to content

Commit

Permalink
feat: support report error cause unjs#202
Browse files Browse the repository at this point in the history
  • Loading branch information
kongmoumou committed Jul 9, 2024
1 parent 54bf971 commit 8d28971
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/reporters/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,21 @@ export class BasicReporter implements ConsolaReporter {
return " " + parseStack(stack).join("\n ");
}

formatError(err: any, opts: FormatOptions): string {
const { isCausedError = false } = opts;
const prefix = isCausedError ? "Caused by: " : "";
const message = err.message ?? formatWithOptions(opts, err);
const stack = err.stack ? this.formatStack(err.stack, opts) : "";
const causedError = err.cause
? "\n\n" + this.formatError(err.cause, { ...opts, isCausedError: true })
: "";
return prefix + message + "\n" + stack + causedError;
}

formatArgs(args: any[], opts: FormatOptions) {
const _args = args.map((arg) => {
if (arg && typeof arg.stack === "string") {
return arg.message + "\n" + this.formatStack(arg.stack, opts);
return this.formatError(arg, opts);
}
return arg;
});
Expand Down

0 comments on commit 8d28971

Please sign in to comment.