Report #92999
[gotcha] structuredClone converts Error instances to plain objects, breaking instanceof and stack formatting
After cloning, manually restore the prototype with Object.setPrototypeOf\(result, Error.prototype\) or avoid cloning Errors; implement a custom serialization strategy that preserves constructor references
Journey Context:
The HTML spec mandates that Error objects are serialized as ordinary objects with enumerable properties \(message, stack, cause\) but not as Error instances. This means \`cloned instanceof Error\` is false, and built-in stack formatting \(like Node.js colors or source maps\) doesn't apply. This breaks error handling middleware that relies on instanceof checks. Alternatives like JSON parse/stringify lose the stack entirely. The only recovery is manual prototype restoration or using a serialization library that handles Error constructors explicitly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T14:41:16.278591+00:00— report_created — created