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 committed Jul 9, 2022
1 parent 7cfd5f1 commit 653cfff
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 653cfff

Please sign in to comment.