mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
util: serialize falsy cause values while inspecting errors
Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de> PR-URL: https://github.com/nodejs/node/pull/41097 Fixes: https://github.com/nodejs/node/issues/41096 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
This commit is contained in:
1 parent
89d955658b
commit
2602c0ca62
2 files changed
+12
-1
No files matched your search
@@ -1282,7 +1282,8 @@ function formatError(err, constructor, tag, ctx, keys) {
|
||||
|
||||
removeDuplicateErrorKeys(ctx, keys, err, stack);
|
||||
|
||||
if (err.cause && (keys.length === 0 || !keys.includes('cause'))) {
|
||||
if (err.cause !== undefined &&
|
||||
(keys.length === 0 || !keys.includes('cause'))) {
|
||||
keys.push('cause');
|
||||
}
|
||||
|
||||
|
||||
@@ -660,6 +660,16 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324');
|
||||
assert(ex.includes('[message]'));
|
||||
}
|
||||
|
||||
{
|
||||
const falsyCause1 = new Error('', { cause: false });
|
||||
delete falsyCause1.stack;
|
||||
const falsyCause2 = new Error(undefined, { cause: null });
|
||||
falsyCause2.stack = '';
|
||||
|
||||
assert.strictEqual(util.inspect(falsyCause1), '[Error] { [cause]: false }');
|
||||
assert.strictEqual(util.inspect(falsyCause2), '[Error] { [cause]: null }');
|
||||
}
|
||||
|
||||
{
|
||||
const tmp = Error.stackTraceLimit;
|
||||
Error.stackTraceLimit = 0;
|
||||
|
||||
Reference in new issue
Block a user