Repository navigation
Preserve Error causes during serialization and deserialization - #35
Open
mayankdhingra02 wants to merge 1 commit into
Open
mayankdhingra02 wants to merge 1 commit into
mayankdhingra02 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 testandnpm run coveragepass 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.