{"record":{"id":"8aa28a82c7b7607c","repo":"denoland/deno","slug":"datacloneerror-8aa28a","errorCode":"DataCloneError","errorMessage":"e.message","messagePattern":"e\\.message","errorType":"exception","errorClass":"DOMException","httpStatus":null,"severity":"error","filePath":"ext/web/02_structured_clone.js","lineNumber":141,"sourceCode":"      case \"Float32Array\":\n        Constructor = Float32Array;\n        break;\n      case \"Float64Array\":\n        Constructor = Float64Array;\n        break;\n    }\n    return new Constructor(\n      structuredClone(TypedArrayPrototypeGetBuffer(value)),\n      TypedArrayPrototypeGetByteOffset(value),\n      TypedArrayPrototypeGetLength(value),\n    );\n  }\n\n  try {\n    return core.structuredClone(value);\n  } catch (e) {\n    if (ObjectPrototypeIsPrototypeOf(TypeErrorPrototype, e)) {\n      throw new DOMException(e.message, \"DataCloneError\");\n    }\n    throw e;\n  }\n}\n\nreturn { structuredClone };\n})();\n","sourceCodeStart":123,"sourceCodeEnd":149,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/web/02_structured_clone.js#L123-L149","documentation":"structuredClone delegates to the native structured-clone serializer; when the value graph contains something the algorithm cannot handle (functions, symbols, platform objects without serialization support), the op throws a TypeError which is rewrapped as DOMException DataCloneError carrying the same message (ext/web/02_structured_clone.js:139-143). Only TypeErrors are converted — other exceptions propagate unchanged. This is the same DataCloneError family raised by postMessage on uncloneable data.","triggerScenarios":"structuredClone(() => {}); structuredClone({ cb: function () {} }); structuredClone(Symbol()); cloning an object holding a WebSocket, a Deno platform object, or any class instance whose graph reaches a function or native resource.","commonSituations":"Sending app state over postMessage/worker messages without stripping handlers; deep-cloning request contexts or ORM entities that embed connections; porting Electron-style IPC patterns where arbitrary objects were tolerated; caching objects that contain callbacks.","solutions":["Separate behavior from data: remove functions, symbols, and platform objects before cloning and re-attach them on the receiving side.","Clone only serializable state (plain objects, arrays, typed arrays, Maps/Sets, Dates, primitives) — the validator/reviver pattern.","If class instances matter, convert to plain data first and reconstruct from the clone.","Catch DOMException with name === 'DataCloneError' to emit a targeted error naming the offending key instead of a generic failure."],"exampleFix":"// before\nworker.postMessage(structuredClone(ctx)); // ctx has function handlers -> DataCloneError\n\n// after\nconst { handlers, ...data } = ctx;\nworker.postMessage(structuredClone(data));","handlingStrategy":"try-catch","validationCode":"function isCloneable(v) {\n  try { structuredClone(v); return true; } catch { return false; }\n}\nif (!isCloneable(state)) throw new Error('state contains uncloneable values');","typeGuard":"const isStructuredCloneable = (v) => {\n  try { structuredClone(v); return true; } catch { return false; }\n};","tryCatchPattern":"try {\n  worker.postMessage(structuredClone(payload));\n} catch (e) {\n  if (e instanceof DOMException && e.name === 'DataCloneError') {\n    const { handlers, ...data } = payload;\n    worker.postMessage(structuredClone(data));\n  } else throw e;\n}","preventionTips":["Keep functions, symbols, and platform objects out of cloned state","Clone plain data and revive behavior on the receiver","Type message payloads as plain serializable structures"],"tags":["structured-clone","postmessage","serialization","worker"],"backgroundTag":"data-clone-error","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}