Skip to content

Preserve Error causes during serialization and deserialization - #35

Open
mayankdhingra02 wants to merge 1 commit into
ungap:mainfrom
mayankdhingra02:codex/preserve-error-causes
Open

mayankdhingra02 wants to merge 1 commit into
ungap:mainfrom
mayankdhingra02:codex/preserve-error-causes

Conversation

@mayankdhingra02

Copy link
Copy Markdown

deserialize(serialize(new Error('outer', {cause: new TypeError('inner')}))) loses the nested error. Store an own data-property cause as a record reference and restore it as a non-enumerable property. Caching the error before following its cause preserves shared references and cycles.

Fixes #32.

Accessor and inherited causes are ignored without invoking getters, matching native structuredClone. Legacy records and errors without a cause retain their existing representation. This keeps the existing error-constructor and realm detection behavior; the separate AggregateError constructor issue (#34) is unchanged.

Validation: npm run build, npm test and npm run coverage pass on Node 22 with 100% statement, branch, function and line coverage. Tests also pass on Node 24. Added regression checks for nested causes, primitive/undefined causes, shared references, cycles, descriptors, getter non-invocation and lossy mode. Additional consumer checks cover CJS, ESM, forced polyfill and the regenerated browser JSON bundle. The regression fails on the original implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error causes are dropped by serialize/deserialize

1 participant