Preserve own properties of Error instances across serialization/deserialization#166
Open
aron-cf wants to merge 1 commit intocloudflare:mainfrom
Open
Preserve own properties of Error instances across serialization/deserialization#166aron-cf wants to merge 1 commit intocloudflare:mainfrom
aron-cf wants to merge 1 commit intocloudflare:mainfrom
Conversation
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.
🦋 Changeset detectedLatest commit: 13491be 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
Comment on lines
+17
to
+19
| Property values that cannot be represented over the wire (capabilities without a session, cycles, unsupported types) are silently dropped from the error's property bag; the error itself always reaches the receiver. Use `onSendError` to scrub fields explicitly if you need control over what gets sent. | ||
|
|
||
| The wire format change is backwards-compatible: errors with no extras are still emitted in the legacy 3- or 4-element form, and older peers that only understand that form will simply ignore the new trailing element. |
Contributor
Author
There was a problem hiding this comment.
Happy to make this shorter if we want terser changelog entries.
Comment on lines
+308
to
+311
| // supported type round-trips. If a property's value can't be serialized (a capability | ||
| // without a session, a cycle, an Object.create(null), …) we silently drop it: the | ||
| // error itself must always make it through. Use `onSendError` to scrub heavy or | ||
| // sensitive fields explicitly. |
Contributor
Author
There was a problem hiding this comment.
Would appreciate feedback on whether we just drop the entire property if it fails to serialize rather than making a best effort attempt.
Comment on lines
+189
to
+191
| When `props` is present, `stack` is normalised to `null` if absent so that positional indexing for `props` is unambiguous. When there are no extras, the legacy 3- or 4-element form is emitted unchanged. | ||
|
|
||
| The `props` element is backwards-compatible: a peer that only understands the 4-element form ignores it and recovers the standard `name`/`message`/`stack`. A peer that understands `props` but receives the 3- or 4-element form simply sees no extras. |
Contributor
Author
There was a problem hiding this comment.
Happy to remove this if it's too much information but felt it might be useful to have documented.
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.The wire format change is fully backwards-compatible.
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, and the backwards-compatibility rule.