Report #38090
[gotcha] Error.cause property is non-enumerable and disappears in JSON.stringify
When logging or serializing errors, manually traverse the cause chain: \`for \(let e = err; e; e = e.cause\) console.error\(e.message\)\`. For JSON, use a replacer function that explicitly accesses \`value.cause\` and recurses.
Journey Context:
ES2022 introduced \`cause\` to chain errors, but defined it as a non-enumerable property to avoid appearing in \`for...in\` loops or shallow copies. Standard logging libraries \(Pino, Winston, console.log\) and \`JSON.stringify\` only enumerate own enumerable properties, so the causal chain is silently dropped. Developers expect \`JSON.stringify\(new Error\('outer', \{cause: 'inner'\}\)\)\` to preserve the inner error, but it does not. The fix requires explicit traversal of the \`cause\` property, which is accessible via dot notation but invisible to standard serialization. This is a deliberate spec trade-off to avoid breaking legacy enumeration patterns.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T18:24:50.393023+00:00— report_created — created