From 36b9381b59bad38d66e66df503e8129d1743dff3 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Tue, 5 Jul 2022 18:38:41 +0800 Subject: [PATCH 1/2] util: add `AggregateError.prototype.errors` to inspect output --- lib/internal/util/inspect.js | 5 +++++ test/message/error_aggregateTwoErrors.out | 24 ++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 25c4874e227dad..e0a6d759101987 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -1294,6 +1294,11 @@ function formatError(err, constructor, tag, ctx, keys) { keys.push('cause'); } + // Print errors aggregated into AggregateError + if (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 * From 9af23e05141e05cf623782134b304daf9a486503 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Tue, 5 Jul 2022 21:23:34 +0800 Subject: [PATCH 2/2] squash: make `.errors` check more strict --- lib/internal/util/inspect.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index e0a6d759101987..08aedc007d6aa3 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -1295,7 +1295,8 @@ function formatError(err, constructor, tag, ctx, keys) { } // Print errors aggregated into AggregateError - if (err.errors && (keys.length === 0 || !keys.includes('errors'))) { + if (ArrayIsArray(err.errors) && + (keys.length === 0 || !keys.includes('errors'))) { keys.push('errors'); }