fix: fall back to structured-clone for RPC error envelopes#336
fix: fall back to structured-clone for RPC error envelopes#336baseballyama wants to merge 1 commit into
Conversation
✅ Deploy Preview for devfra ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a WS transport bug in devframe’s RPC layer where jsonSerializable: true methods could crash the serializer when the handler throws, because the error envelope was being strict-JSON encoded (masking the original RPC error and potentially taking the dev server down).
Changes:
- Skip strict-JSON serialization for RPC error envelopes on both WS server and WS client transports (fall back to structured-clone).
- Add a regression test ensuring a thrown
Errorfrom ajsonSerializable: trueRPC results in a rejection rather than a serialization crash.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| devframe/packages/devframe/src/rpc/transports/ws-server.ts | Adjusts WS server-side message serialization to avoid strict-JSON for error envelopes. |
| devframe/packages/devframe/src/rpc/transports/ws-client.ts | Mirrors the same error-envelope serialization behavior on the WS client channel. |
| devframe/packages/devframe/src/rpc/transports/ws.test.ts | Adds a regression test for thrown errors in jsonSerializable: true RPCs over WS. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thanks for the PR! I am sorry I just did a big refactor to move devframe out of the repo, you can resend the PR to https://github.com/devframes/devframe instead? Thanks |
|
I opened devframes/devframe#8 instead. |
Description
jsonSerializable: truedeclares the result shape of an RPC function, but the WS transport appliedstrictJsonStringifyto every outgoing message routed to such a method — including the error envelope ({ t: 's', i, e }) emitted when the handler throws. BecauseErrorinstances aren't JSON-serializable, this crashed the serializer with DF0020 and masked the original DTK0011 entirely, taking the dev server down with it (reproducible on StackBlitz / WebContainer).Skip the strict-JSON path for error envelopes on both ws-server and ws-client transports so thrown values round-trip via structured-clone, and the underlying failure surfaces on the caller instead.
Linked Issues
close: #335
Additional context
N/A