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: nodejs/node#43646
Fixes: nodejs/node#43645
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
LiviaMedeiros authored and guangwong committed Oct 10, 2022
1 parent 324b833 commit 0b126a6
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,5 +9,27 @@ AggregateError: original
at Function.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 Object.Module._extensions..js (node:internal/modules/cjs/loader:*:*)
at Module.load (node:internal/modules/cjs/loader:*:*)
at Function.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 Object.Module._extensions..js (node:internal/modules/cjs/loader:*:*)
at Module.load (node:internal/modules/cjs/loader:*:*)
at Function.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'
}
]
}

0 comments on commit 0b126a6

Please sign in to comment.