Skip to content

util.inspect throws when given a ZodError #60717

@mnahkies

Description

@mnahkies

Version

v24.11.1

Platform

Darwin <hostname> 24.6.0 Darwin Kernel Version 24.6.0: Mon Aug 11 21:16:34 PDT 2025; root:xnu-11417.140.69.701.11~1/RELEASE_ARM64_T6020 arm64

Subsystem

util

What steps will reproduce the bug?

Using [email protected]

const { inspect } = require('node:util');
const { z } = require('zod');

inspect(z.object({ foo: z.string() }).safeParse().error);

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

Seems to happen on any ZodError

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

It should inspect the error, same as it did on Node v22

What do you see instead?

Exception.

node:internal/util/inspect:1183
    if (!isStackOverflowError(err)) throw err;
                                    ^

TypeError: Cannot read properties of undefined (reading 'value')
    at formatProperty (node:internal/util/inspect:2279:12)
    at formatRaw (node:internal/util/inspect:1176:9)
    at formatValue (node:internal/util/inspect:932:10)
    at inspect (node:internal/util/inspect:409:10)
    at Object.<anonymous> (/junk.js:4:1)
    at Module._compile (node:internal/modules/cjs/loader:1761:14)
    at Object..js (node:internal/modules/cjs/loader:1893:10)
    at Module.load (node:internal/modules/cjs/loader:1481:32)
    at Module._load (node:internal/modules/cjs/loader:1300:12)
    at TracingChannel.traceSync (node:diagnostics_channel:328:14)

Node.js v24.11.1

Additional information

I believe this is a regression caused by 748d4f6 - based on the timing / line numbers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.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