Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
util: inspect: do not crash on an Error stack pointing to itself
  • Loading branch information
SamVerschueren committed May 6, 2025
commit 8b819f9240e12d3a07fb334085222008e99b87d1
4 changes: 3 additions & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,9 @@ function getStackString(ctx, error) {
if (typeof error.stack === 'string') {
return error.stack;
}
return formatValue(ctx, error.stack);
if (error.stack !== error) {
return formatValue(ctx, error.stack);
}
Comment thread
BridgeAR marked this conversation as resolved.
Resolved
}
return ErrorPrototypeToString(error);
}
Expand Down
19 changes: 19 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3460,3 +3460,22 @@ ${error.stack.split('\n').slice(1).join('\n')}`,
'[[\n Symbol(foo)\n]]'
);
}

{
const prepareStackTrace = Error.prepareStackTrace;

Error.prepareStackTrace = (error) => error;

const error = new Error('foo');

assert.strictEqual(inspect(error), '[Error: foo]');

Error.prepareStackTrace = prepareStackTrace;
}

{
const error = new Error('foo');
error.stack = error

assert.strictEqual(inspect(error), '[Error: foo]');
}