Skip to content

Returning error in prepareStackTrace exceeds maximum callstack size #58195

Open
@SamVerschueren

Description

@SamVerschueren

Version

22.15.0

Platform

Darwin Sams-MacBook-Pro-2.local 24.3.0 Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:22 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6041 arm64

Subsystem

No response

What steps will reproduce the bug?

Since this PR #56573 the following code causes a Maximum call stack size exceeded error

Error.prepareStackTrace = (error) => error;

console.log(new Error('foo').stack);
//=> 💥 Maximum call stack size exceeded

It basically happens if error.stack points to the error itself

const err = new Error('foo');
err.stack = err;

console.log(err);

How often does it reproduce? Is there a required condition?

No

What is the expected behavior? Why is that the expected behavior?

Before that PR, it just printed the error

Error.prepareStackTrace = (error) => error;

console.log(new Error('unicorn').stack);
//=> [Error foo]
const err = new Error('foo');
err.stack = err;

console.log(err);
//=> [Error foo]

What do you see instead?

💥 Maximum call stack size exceeded

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    utilIssues and PRs related to the built-in util module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions