Report #104529
[gotcha] structuredClone throws on Error objects and other non-cloneable types without clear error messages
Before calling structuredClone, wrap the operation in a try-catch, or use a custom deep clone function that handles non-cloneable types gracefully \(e.g., by copying enumerable properties\). For Error objects, consider serializing them manually \(e.g., \{ name, message, stack \}\).
Journey Context:
The HTML structured clone algorithm \(specified in the HTML Living Standard\) defines a list of cloneable types: primitives, Boolean/String/Number objects, Date, RegExp, Blob, File, FileList, ImageData, ArrayBuffer, Map, Set, and plain objects/arrays. Error objects, functions, Symbols, and DOM nodes are not cloneable and will cause a DataCloneError. The spec does not mention this in most introductory resources, and the error message is often generic \(e.g., 'Failed to execute 'structuredClone' on 'Window': ...'\). The recommended pattern is to pre-process the data, or use a library like lodash.cloneDeep that falls back to property enumeration. Note that even if you try to ignore errors, structuredClone will throw synchronously, breaking the entire operation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-08-30T20:11:23.038180+00:00— report_created — created