fix: preserve typed error as cause in SSE errors#315
Conversation
Summary of ChangesHello @birdayz, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request improves error handling within the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
🧪 Code Coverage
Generated by coverage-comment.yml |
There was a problem hiding this comment.
Code Review
The pull request modifies src/client/transports/json_rpc_transport.ts to enhance error handling. Specifically, when an SSE event contains an error, the thrown Error object now includes a cause property. This cause is populated by mapping the JSONRPCErrorResponse using JsonRpcTransport.mapToError, providing more detailed context for the error.
ishymko
left a comment
There was a problem hiding this comment.
Thank you for the PR!
Error handling definitely requires improvements here (i.e. using predefined transport-agnostic errors across all transports in a consistent way and documenting them at the client level). It'll hopefully improve for 1.0 release as we'll be able to drop some backward compatible leftovers from #169 required for #198.
2ce0057 to
90b3a60
Compare
When an SSE stream contains a JSON-RPC error, we throw an Error with
a formatted message string. The structured error data (code, message,
data) is lost, forcing consumers to parse it back out of the string.
Wrap the typed error from mapToError() as the cause. This preserves
backward compatibility (same message string) while exposing the
structured error via error.cause.errorResponse.error.
Consumers can now do:
const cause = error.cause as JSONRPCTransportError;
const { code, message, data } = cause.errorResponse.error;
90b3a60 to
4d02052
Compare
🤖 I have created a release *beep* *boop* --- ## [0.3.10](v0.3.9...v0.3.10) (2026-01-27) ### Bug Fixes * do not use ReadableStream async iterator in SSE stream parsing ([#311](#311)) ([5359fa8](5359fa8)) * preserve typed error as cause in SSE errors ([#315](#315)) ([d39544e](d39544e)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
What
Wrap the typed error from
mapToError()as thecausewhen throwing SSE stream errors.Why
When an SSE stream contains a JSON-RPC error, we throw an Error with a formatted message string. The structured error data (code, message, data) is serialized into that string and lost. Consumers who need the structured data have to parse it back out with regex.
Implementation details
Use the standard JS error
causeoption to preserve the typed error:Backward compatible - the message string is unchanged. Consumers can access structured data via: