mirror of
https://github.com/denoland/deno.git
synced 2025-09-29 13:44:47 +00:00
feat: Better formatting for AggregateError (#14285)
This commit adds "aggregated" field to "deno_core::JsError" that stores instances of "JsError" recursively to properly handle "AggregateError" formatting. Appropriate logics was added to "PrettyJsError" and "console" API to format AggregateErrors. Co-authored-by: Nayeem Rahman <nayeemrmn99@gmail.com>
This commit is contained in:
parent
0bb96cde72
commit
a87be28a46
10 changed files with 210 additions and 78 deletions
|
@ -2714,3 +2714,15 @@ itest!(set_timeout_error_handled {
|
|||
args: "run --quiet set_timeout_error_handled.ts",
|
||||
output: "set_timeout_error_handled.ts.out",
|
||||
});
|
||||
|
||||
itest!(aggregate_error {
|
||||
args: "run --quiet aggregate_error.ts",
|
||||
output: "aggregate_error.out",
|
||||
exit_code: 1,
|
||||
});
|
||||
|
||||
itest!(complex_error {
|
||||
args: "run --quiet complex_error.ts",
|
||||
output: "complex_error.ts.out",
|
||||
exit_code: 1,
|
||||
});
|
||||
|
|
18
cli/tests/testdata/aggregate_error.out
vendored
Normal file
18
cli/tests/testdata/aggregate_error.out
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
AggregateError: Multiple errors.
|
||||
at [WILDCARD]/aggregate_error.ts:1:24
|
||||
|
||||
AggregateError: Multiple errors.
|
||||
Error: Error message 1.
|
||||
at [WILDCARD]/aggregate_error.ts:2:3
|
||||
Error: Error message 2.
|
||||
at [WILDCARD]/aggregate_error.ts:3:3
|
||||
at [WILDCARD]/aggregate_error.ts:1:24
|
||||
|
||||
error: Uncaught AggregateError: Multiple errors.
|
||||
Error: Error message 1.
|
||||
at [WILDCARD]/aggregate_error.ts:2:3
|
||||
Error: Error message 2.
|
||||
at [WILDCARD]/aggregate_error.ts:3:3
|
||||
const aggregateError = new AggregateError([
|
||||
^
|
||||
at [WILDCARD]/aggregate_error.ts:1:24
|
9
cli/tests/testdata/aggregate_error.ts
vendored
Normal file
9
cli/tests/testdata/aggregate_error.ts
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
const aggregateError = new AggregateError([
|
||||
new Error("Error message 1."),
|
||||
new Error("Error message 2."),
|
||||
], "Multiple errors.");
|
||||
console.log(aggregateError.stack);
|
||||
console.log();
|
||||
console.log(aggregateError);
|
||||
console.log();
|
||||
throw aggregateError;
|
18
cli/tests/testdata/complex_error.ts
vendored
Normal file
18
cli/tests/testdata/complex_error.ts
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
const error = new AggregateError(
|
||||
[
|
||||
new AggregateError([new Error("qux1"), new Error("quux1")]),
|
||||
new Error("bar1", { cause: new Error("baz1") }),
|
||||
],
|
||||
"foo1",
|
||||
{
|
||||
cause: new AggregateError([
|
||||
new AggregateError([new Error("qux2"), new Error("quux2")]),
|
||||
new Error("bar2", { cause: new Error("baz2") }),
|
||||
], "foo2"),
|
||||
},
|
||||
);
|
||||
console.log(error.stack);
|
||||
console.log();
|
||||
console.log(error);
|
||||
console.log();
|
||||
throw error;
|
44
cli/tests/testdata/complex_error.ts.out
vendored
Normal file
44
cli/tests/testdata/complex_error.ts.out
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
AggregateError: foo1
|
||||
at [WILDCARD]/complex_error.ts:1:15
|
||||
|
||||
AggregateError: foo1
|
||||
AggregateError
|
||||
Error: qux1
|
||||
at [WILDCARD]/complex_error.ts:3:25
|
||||
Error: quux1
|
||||
at [WILDCARD]/complex_error.ts:3:44
|
||||
at [WILDCARD]/complex_error.ts:3:5
|
||||
Error: bar1
|
||||
at [WILDCARD]/complex_error.ts:4:5
|
||||
Caused by Error: baz1
|
||||
at [WILDCARD]/complex_error.ts:4:32
|
||||
at [WILDCARD]/complex_error.ts:1:15
|
||||
Caused by AggregateError: foo2
|
||||
at [WILDCARD]/complex_error.ts:8:12
|
||||
|
||||
error: Uncaught AggregateError: foo1
|
||||
AggregateError
|
||||
Error: qux1
|
||||
at [WILDCARD]/complex_error.ts:3:25
|
||||
Error: quux1
|
||||
at [WILDCARD]/complex_error.ts:3:44
|
||||
at [WILDCARD]/complex_error.ts:3:5
|
||||
Error: bar1
|
||||
at [WILDCARD]/complex_error.ts:4:5
|
||||
Caused by: Error: baz1
|
||||
at [WILDCARD]/complex_error.ts:4:32
|
||||
const error = new AggregateError(
|
||||
^
|
||||
at [WILDCARD]/complex_error.ts:1:15
|
||||
Caused by: AggregateError: foo2
|
||||
AggregateError
|
||||
Error: qux2
|
||||
at [WILDCARD]/complex_error.ts:9:27
|
||||
Error: quux2
|
||||
at [WILDCARD]/complex_error.ts:9:46
|
||||
at [WILDCARD]/complex_error.ts:9:7
|
||||
Error: bar2
|
||||
at [WILDCARD]/complex_error.ts:10:7
|
||||
Caused by: Error: baz2
|
||||
at [WILDCARD]/complex_error.ts:10:34
|
||||
at [WILDCARD]/complex_error.ts:8:12
|
8
cli/tests/testdata/error_cause.ts.out
vendored
8
cli/tests/testdata/error_cause.ts.out
vendored
|
@ -6,12 +6,10 @@ error: Uncaught Error: foo
|
|||
at b (file:///[WILDCARD]/error_cause.ts:7:3)
|
||||
at c (file:///[WILDCARD]/error_cause.ts:11:3)
|
||||
at file:///[WILDCARD]/error_cause.ts:14:1
|
||||
Caused by: Uncaught Error: bar
|
||||
throw new Error("foo", { cause: new Error("bar", { cause: "deno" as any }) });
|
||||
^
|
||||
Caused by: Error: bar
|
||||
at a (file:///[WILDCARD]/error_cause.ts:3:35)
|
||||
at b (file:///[WILDCARD]/error_cause.ts:7:3)
|
||||
at c (file:///[WILDCARD]/error_cause.ts:11:3)
|
||||
at file:///[WILDCARD]/error_cause.ts:14:1
|
||||
Caused by: Uncaught deno
|
||||
[WILDCARD]
|
||||
Caused by: deno
|
||||
[WILDCARD]
|
||||
|
|
10
cli/tests/testdata/error_cause_recursive.ts.out
vendored
10
cli/tests/testdata/error_cause_recursive.ts.out
vendored
|
@ -3,12 +3,8 @@ error: Uncaught Error: bar
|
|||
const y = new Error("bar", { cause: x });
|
||||
^
|
||||
at file:///[WILDCARD]/error_cause_recursive.ts:2:11
|
||||
Caused by: Uncaught Error: foo
|
||||
const x = new Error("foo");
|
||||
^
|
||||
Caused by: Error: foo
|
||||
at file:///[WILDCARD]/error_cause_recursive.ts:1:11
|
||||
Caused by: Uncaught Error: bar
|
||||
const y = new Error("bar", { cause: x });
|
||||
^
|
||||
Caused by: Error: bar
|
||||
at file:///[WILDCARD]/error_cause_recursive.ts:2:11
|
||||
[WILDCARD]
|
||||
[WILDCARD]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue