Preserve own properties of Error instances across serialization/deserialization#166
Merged
kentonv merged 2 commits intocloudflare:mainfrom May 8, 2026
Merged
Conversation
🦋 Changeset detectedLatest commit: 9025285 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
aron-cf
commented
Apr 30, 2026
aron-cf
commented
May 7, 2026
aron-cf
commented
May 7, 2026
kentonv
reviewed
May 7, 2026
aron-cf
commented
May 8, 2026
Contributor
Author
aron-cf
left a comment
There was a problem hiding this comment.
I've reworked the code to skip any error properties that fail to serialize. I've done this in a pre-scan pass (that early exits when it hits a negative) rather than attempting to recover from a serialization error, from what I understand this removes the risk of leaking ReadableStreams at the cost of two passes. Let me know your thoughts.
This commit ensures that own properties are sent across the RPC boundary and reconstructed on the Error instance on the other side. The `cause` field and, in the case of `errors` for `AggregateError` are also copied over.
kentonv
approved these changes
May 8, 2026
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.
Closes #87.
Today the wire format for
Erroronly carriesname,message, and (optionally)stack. Anything a user attaches to the error —code,details, acause, the inner errors of anAggregateError— is lost the moment the error crosses an RPC boundary.This PR extends the
errorexpression with an optional fifth element,props. This uses the same serialization/deserialization as any other object.Error.causeandAggregateError.errorsare normally non-enumerable, so they are picked up explicitly by the encoder. On the receive side, the decoder constructs the error as before and then assigns each entry frompropsas an own enumerable property on the result.Properties that cannot be fully serialized are dropped.
Tests have been added to verify the serialization/deserialization of various different error cases and failure modes. There may be too many, happy to remove any if needed.
The
errorexpression in protocol.md now documents the optionalpropselement, the lossy-fallback semantics.