Version
v24.11.1
Platform
Darwin Kernel Version 25.1.0 (macOS)
Also reproduces in Linux containers running Node 24.11.1
Subsystem
util
What steps will reproduce the bug?
// Mimicking ZodError's structure more closely
class ZodLikeError extends Error {
constructor(issues) {
super();
const actualProto = new.target.prototype;
if (Object.setPrototypeOf) {
Object.setPrototypeOf(this, actualProto);
} else {
this.__proto__ = actualProto;
}
this.name = "ZodLikeError";
this.issues = issues;
}
get errors() {
return this.issues;
}
get message() {
return JSON.stringify(this.issues, null, 2);
}
toString() {
return this.message;
}
get isEmpty() {
return this.issues.length === 0;
}
format(_mapper) {
const mapper =
_mapper ||
function (issue) {
return issue.message;
};
const fieldErrors = { _errors: [] };
return fieldErrors;
}
flatten(mapper = (issue) => issue.message) {
const fieldErrors = {};
const formErrors = [];
for (const sub of this.issues) {
if (sub.path.length > 0) {
const firstEl = sub.path[0];
fieldErrors[firstEl] = fieldErrors[firstEl] || [];
fieldErrors[firstEl].push(mapper(sub));
} else {
formErrors.push(mapper(sub));
}
}
return { formErrors, fieldErrors };
}
get formErrors() {
return this.flatten();
}
}
const issues = [
{
code: "invalid_type",
expected: "object",
received: "string",
path: [],
message: "Expected object, received string",
},
];
console.log("Test: Creating ZodLikeError...");
const zodLikeError = new ZodLikeError(issues);
console.log("✅ Error created");
console.log("Error type:", zodLikeError.constructor.name);
console.log("");
console.log("Test: Attempting to log with console.error...");
try {
console.error("ZodLikeError object:", zodLikeError);
console.log("✅ console.error succeeded - no crash!");
} catch (consoleErrorBug) {
console.log("❌ console.error CRASHED!");
console.log("Crash message:", consoleErrorBug.message);
console.log("");
console.log("Full stack trace:");
console.log(consoleErrorBug.stack);
}
How often does it reproduce? Is there a required condition?
Reproduces 100% of the time in Node v24.11.1 when logging ZodError objects from the zod library (v3.23.8).
Required conditions:
- Node.js version must be 24.11.1 (does NOT reproduce in 24.11.0)
- Error object must be a ZodError from the zod library
This appears to be a regression introduced in Node 24.11.1.
What is the expected behavior? Why is that the expected behavior?
console.error() should successfully format and log the error object without crashing, just as it does in Node 24.11.0 and earlier versions.
In my test code:
Error object: ZodLikeError: [
{
"code": "invalid_type",
"expected": "object",
"received": "string",
"path": [],
"message": "Expected object, received string"
}
]
What do you see instead?
Process crashes with:
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 formatWithOptionsInternal (node:internal/util/inspect:2644:40)
at formatWithOptions (node:internal/util/inspect:2506:10)
at console.value (node:internal/console/constructor:356:14)
at console.error (node:internal/console/constructor:423:61)
Additional information
This is a regression between Node 24.11.0 (works) and 24.11.1 (crashes).
Testing results:
✅ Node v24.11.0: Works correctly, no crash
❌ Node v24.11.1: Crashes every time
Version
v24.11.1
Platform
Subsystem
util
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Reproduces 100% of the time in Node v24.11.1 when logging ZodError objects from the zod library (v3.23.8).
Required conditions:
This appears to be a regression introduced in Node 24.11.1.
What is the expected behavior? Why is that the expected behavior?
console.error() should successfully format and log the error object without crashing, just as it does in Node 24.11.0 and earlier versions.
In my test code:
What do you see instead?
Process crashes with:
Additional information
This is a regression between Node 24.11.0 (works) and 24.11.1 (crashes).
Testing results:
✅ Node v24.11.0: Works correctly, no crash
❌ Node v24.11.1: Crashes every time