mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
util: fix inspecting error with a throwing getter for cause
PR-URL: https://github.com/nodejs/node/pull/47163 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
parent
841f6b3abf
commit
863ac8fa37
|
|
@ -1243,9 +1243,16 @@ function getStackString(error) {
|
||||||
function getStackFrames(ctx, err, stack) {
|
function getStackFrames(ctx, err, stack) {
|
||||||
const frames = StringPrototypeSplit(stack, '\n');
|
const frames = StringPrototypeSplit(stack, '\n');
|
||||||
|
|
||||||
|
let cause;
|
||||||
|
try {
|
||||||
|
({ cause } = err);
|
||||||
|
} catch {
|
||||||
|
// If 'cause' is a getter that throws, ignore it.
|
||||||
|
}
|
||||||
|
|
||||||
// Remove stack frames identical to frames in cause.
|
// Remove stack frames identical to frames in cause.
|
||||||
if (err.cause && isError(err.cause)) {
|
if (cause != null && isError(cause)) {
|
||||||
const causeStack = getStackString(err.cause);
|
const causeStack = getStackString(cause);
|
||||||
const causeStackStart = StringPrototypeIndexOf(causeStack, '\n at');
|
const causeStackStart = StringPrototypeIndexOf(causeStack, '\n at');
|
||||||
if (causeStackStart !== -1) {
|
if (causeStackStart !== -1) {
|
||||||
const causeFrames = StringPrototypeSplit(StringPrototypeSlice(causeStack, causeStackStart + 1), '\n');
|
const causeFrames = StringPrototypeSplit(StringPrototypeSlice(causeStack, causeStackStart + 1), '\n');
|
||||||
|
|
|
||||||
|
|
@ -46,3 +46,9 @@ process.nextTick(() => {
|
||||||
console.log(inspect(cause3));
|
console.log(inspect(cause3));
|
||||||
console.log(inspect(error2));
|
console.log(inspect(error2));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
{
|
||||||
|
const error = new Error('cause that throws');
|
||||||
|
Reflect.defineProperty(error, 'cause', { get() { throw new Error(); } });
|
||||||
|
console.log(inspect(error));
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,16 @@ Error: undefined cause
|
||||||
at * {
|
at * {
|
||||||
[cause]: undefined
|
[cause]: undefined
|
||||||
}
|
}
|
||||||
|
Error: cause that throws
|
||||||
|
at *
|
||||||
|
at *
|
||||||
|
at *
|
||||||
|
at *
|
||||||
|
at *
|
||||||
|
at *
|
||||||
|
at * {
|
||||||
|
[cause]: [Getter]
|
||||||
|
}
|
||||||
RangeError: New Stack Frames
|
RangeError: New Stack Frames
|
||||||
at *
|
at *
|
||||||
*[90m at *[39m {
|
*[90m at *[39m {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user