mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
util: make sure error causes of any type may be inspected
An error cause may be of any type. Handle all of them, no matter if they are an error or not. Fixes: https://github.com/nodejs/node/issues/41096 Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de> PR-URL: https://github.com/nodejs/node/pull/41097 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
4569674e39
commit
1133796dbf
3 files changed
+39
-1
No files matched your search
@@ -1215,7 +1215,7 @@ function getStackFrames(ctx, err, stack) {
|
||||
const frames = stack.split('\n');
|
||||
|
||||
// Remove stack frames identical to frames in cause.
|
||||
if (err.cause) {
|
||||
if (err.cause && isError(err.cause)) {
|
||||
const causeStack = getStackString(err.cause);
|
||||
const causeStackStart = causeStack.indexOf('\n at');
|
||||
if (causeStackStart !== -1) {
|
||||
|
||||
@@ -13,6 +13,19 @@ const cause2 = new FoobarError('Individual message', { cause: cause1 });
|
||||
cause2.extraProperties = 'Yes!';
|
||||
const cause3 = new Error('Stack causes', { cause: cause2 });
|
||||
|
||||
const cause4 = new Error('Number error cause', { cause: 42 });
|
||||
const cause5 = new Error('Object cause', {
|
||||
cause: {
|
||||
message: 'Unique',
|
||||
name: 'Error',
|
||||
stack: 'Error: Unique\n' +
|
||||
' at Module._compile (node:internal/modules/cjs/loader:827:30)'
|
||||
}
|
||||
});
|
||||
|
||||
console.log(cause4);
|
||||
console.log(cause5);
|
||||
|
||||
process.nextTick(() => {
|
||||
const error = new RangeError('New Stack Frames', { cause: cause2 });
|
||||
const error2 = new RangeError('New Stack Frames', { cause: cause3 });
|
||||
|
||||
@@ -1,3 +1,28 @@
|
||||
Error: Number error cause
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at * {
|
||||
[cause]: 42
|
||||
}
|
||||
Error: Object cause
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at * {
|
||||
[cause]: {
|
||||
message: 'Unique',
|
||||
name: 'Error',
|
||||
stack: 'Error: Unique\n' +
|
||||
' at Module._compile (node:internal/modules/cjs/loader:827:30)'
|
||||
}
|
||||
}
|
||||
RangeError: New Stack Frames
|
||||
at *
|
||||
*[90m at *[39m {
|
||||
|
||||
Reference in new issue
Block a user