Skip to content

util.inspect crashes with a getter whose error.message throws #60683

@yvele

Description

@yvele

Version

v20.19.5, v22.19.0, v24.8.0

Platform

Darwin MacBook-Pro-M1.local 24.6.0 Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:29 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6000 arm64

Subsystem

Util

What steps will reproduce the bug?

const error = {
  // The error message itself is a getter that throws
  get message() { throw new Error('Oops'); }
};

const thrower = {
  get foo() { throw error; }
};

util.inspect(thrower, { getters: true });

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

Every time.

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

Simply return the object getter as "<Inspection threw>" without the message that threw.

What do you see instead?

$ node -e 'util.inspect({get foo() { throw{ get message() { throw new Error }} }}, { getters: true })'
node:internal/util/inspect:1435
    if (!isStackOverflowError(err)) throw err;
                                    ^

Error
    at get message ([eval]:1:56)
    at formatProperty (node:internal/util/inspect:2560:51)
    at formatRaw (node:internal/util/inspect:1428:9)
    at formatValue (node:internal/util/inspect:1183:10)
    at Object.inspect (node:internal/util/inspect:409:10)
    at [eval]:1:6
    at runScriptInThisContext (node:internal/vm:219:10)
    at node:internal/process/execution:451:12
    at [eval]-wrapper:6:24
    at runScriptInContext (node:internal/process/execution:449:60)

Node.js v26.0.0-pre

Additional information

Related to another issue 3 weeks ago:

This issue also highlights robustness concerns described in OWASP 2025 (A10 – Mishandling of Exceptional Conditions):

Catching and handling exceptional conditions ensures that the underlying infrastructure of our programs are not left to deal with unpredictable situations.

Note that I did not encounter this problem in real-world objects; I discovered it by reading the Node.js source code while investigating behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions