Skip to content

Commit

Permalink
util: add AggregateError.prototype.errors to inspect output
Browse files Browse the repository at this point in the history
PR-URL: #43646
Fixes: #43645
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
  • Loading branch information
LiviaMedeiros authored and targos committed Jul 12, 2022
1 parent bdca4d3 commit 5a5c4be
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,12 @@ function formatError(err, constructor, tag, ctx, keys) {
keys.push('cause');
}

// Print errors aggregated into AggregateError
if (ArrayIsArray(err.errors) &&
(keys.length === 0 || !keys.includes('errors'))) {
keys.push('errors');
}

stack = improveStack(stack, constructor, name, tag);

// Ignore the error message if it's contained in the stack.
Expand Down
24 changes: 23 additions & 1 deletion test/message/error_aggregateTwoErrors.out
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,29 @@ AggregateError: original
at Module._load (node:internal/modules/cjs/loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:* {
code: 'ERR0'
code: 'ERR0',
[errors]: [
Error: original
at Object.<anonymous> (*test*message*error_aggregateTwoErrors.js:*:*)
at Module._compile (node:internal/modules/cjs/loader:*:*)
at Module._extensions..js (node:internal/modules/cjs/loader:*:*)
at Module.load (node:internal/modules/cjs/loader:*:*)
at Module._load (node:internal/modules/cjs/loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:* {
code: 'ERR0'
},
Error: second error
at Object.<anonymous> (*test*message*error_aggregateTwoErrors.js:*:*)
at Module._compile (node:internal/modules/cjs/loader:*:*)
at Module._extensions..js (node:internal/modules/cjs/loader:*:*)
at Module.load (node:internal/modules/cjs/loader:*:*)
at Module._load (node:internal/modules/cjs/loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:* {
code: 'ERR1'
}
]
}

Node.js *

0 comments on commit 5a5c4be

Please sign in to comment.