Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support report error cause #308

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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;
}

Check warning on line 27 in src/reporters/basic.ts

View check run for this annotation

Codecov / codecov/patch

src/reporters/basic.ts#L19-L27

Added lines #L19 - L27 were not covered by tests

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);

Check warning on line 32 in src/reporters/basic.ts

View check run for this annotation

Codecov / codecov/patch

src/reporters/basic.ts#L32

Added line #L32 was not covered by tests
}
return arg;
});
Expand Down