Skip to content

Commit 5a5c4be

Browse files
LiviaMedeirostargos
authored andcommitted
util: add AggregateError.prototype.errors to inspect output
PR-URL: #43646 Fixes: #43645 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent bdca4d3 commit 5a5c4be

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/internal/util/inspect.js

+6
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,12 @@ function formatError(err, constructor, tag, ctx, keys) {
13521352
keys.push('cause');
13531353
}
13541354

1355+
// Print errors aggregated into AggregateError
1356+
if (ArrayIsArray(err.errors) &&
1357+
(keys.length === 0 || !keys.includes('errors'))) {
1358+
keys.push('errors');
1359+
}
1360+
13551361
stack = improveStack(stack, constructor, name, tag);
13561362

13571363
// Ignore the error message if it's contained in the stack.

test/message/error_aggregateTwoErrors.out

+23-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,29 @@ AggregateError: original
99
at Module._load (node:internal/modules/cjs/loader:*:*)
1010
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
1111
at node:internal/main/run_main_module:*:* {
12-
code: 'ERR0'
12+
code: 'ERR0',
13+
[errors]: [
14+
Error: original
15+
at Object.<anonymous> (*test*message*error_aggregateTwoErrors.js:*:*)
16+
at Module._compile (node:internal/modules/cjs/loader:*:*)
17+
at Module._extensions..js (node:internal/modules/cjs/loader:*:*)
18+
at Module.load (node:internal/modules/cjs/loader:*:*)
19+
at Module._load (node:internal/modules/cjs/loader:*:*)
20+
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
21+
at node:internal/main/run_main_module:*:* {
22+
code: 'ERR0'
23+
},
24+
Error: second error
25+
at Object.<anonymous> (*test*message*error_aggregateTwoErrors.js:*:*)
26+
at Module._compile (node:internal/modules/cjs/loader:*:*)
27+
at Module._extensions..js (node:internal/modules/cjs/loader:*:*)
28+
at Module.load (node:internal/modules/cjs/loader:*:*)
29+
at Module._load (node:internal/modules/cjs/loader:*:*)
30+
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
31+
at node:internal/main/run_main_module:*:* {
32+
code: 'ERR1'
33+
}
34+
]
1335
}
1436

1537
Node.js *

0 commit comments

Comments
 (0)