From 653cfff22318dff2ecefc1ad561daab7452328f3 Mon Sep 17 00:00:00 2001 From: Livia Medeiros <74449973+LiviaMedeiros@users.noreply.github.com> Date: Sun, 10 Jul 2022 00:01:02 +0800 Subject: [PATCH] util: add `AggregateError.prototype.errors` to inspect output PR-URL: https://github.com/nodejs/node/pull/43646 Fixes: https://github.com/nodejs/node/issues/43645 Reviewed-By: Ruben Bridgewater Reviewed-By: Antoine du Hamel --- lib/internal/util/inspect.js | 6 ++++++ test/message/error_aggregateTwoErrors.out | 24 ++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index fe86189ce68cb3..0ff86d92970ca5 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -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. diff --git a/test/message/error_aggregateTwoErrors.out b/test/message/error_aggregateTwoErrors.out index 34f56f450deb94..9dd1b206f15208 100644 --- a/test/message/error_aggregateTwoErrors.out +++ b/test/message/error_aggregateTwoErrors.out @@ -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. (*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. (*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 *