Closed
Description
Version
master
Platform
N/A
Subsystem
util
What steps will reproduce the bug?
./node -p "new Error('test', { cause: 42 })"
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior?
It should be able to serialize non-error causes.
What do you see instead?
$ ./node -p "new Error('test', { cause: 42 })"
node:internal/util/inspect:1194
return error.stack ? String(error.stack) : ErrorPrototypeToString(error);
^
TypeError: Method Error.prototype.toString called on incompatible receiver 42
at Number.toString (<anonymous>)
at getStackString (node:internal/util/inspect:1194:46)
at getStackFrames (node:internal/util/inspect:1202:24)
at formatError (node:internal/util/inspect:1284:19)
at formatRaw (node:internal/util/inspect:943:14)
at formatValue (node:internal/util/inspect:798:10)
at inspect (node:internal/util/inspect:345:10)
at formatWithOptionsInternal (node:internal/util/inspect:2140:40)
at formatWithOptions (node:internal/util/inspect:2006:10)
at console.value (node:internal/console/constructor:323:14)
Node.js v18.0.0-pre
Additional information
No response