fix: Catch handler errors instead of killing the connection (#131)#114
Merged
benbrandt merged 2 commits intoagentclientprotocol:mainfrom Apr 16, 2026
Merged
Conversation
Instead of propagating handler errors via ? (which tears down the connection), catch them in dispatch_dispatch and report them back to the remote side: - Requests: send a JSON-RPC error response with the original request id - Notifications: send an out-of-band error notification - The connection stays alive for subsequent messages This is an alternative to the match_request/match_notification API approach. Rather than changing the handler API, errors are caught at the dispatch level — like a web server catching unhandled exceptions. Also migrates parse_message impls from json_cast to json_cast_params so deserialization failures produce -32602 (Invalid params) instead of -32700 (Parse error), which is the correct JSON-RPC error code.
nikomatsakis
commented
Apr 16, 2026
| assert_eq!(response["id"], 1); | ||
| assert!(response["error"].is_object(), "Expected error object"); | ||
| assert_eq!( | ||
| response["error"]["code"], -32602, |
Contributor
Author
There was a problem hiding this comment.
compare against the constant defined in the error type, I think
benbrandt
approved these changes
Apr 16, 2026
Member
benbrandt
left a comment
There was a problem hiding this comment.
This is great and much simpler ❤️ thank you!
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.
Instead of propagating handler errors via ? (which tears down the connection), catch them in dispatch_dispatch and report them back to the remote side:
This is an alternative to the match_request/match_notification API approach. Rather than changing the handler API, errors are caught at the dispatch level — like a web server catching unhandled exceptions.
Also migrates parse_message impls from json_cast to json_cast_params so deserialization failures produce -32602 (Invalid params) instead of -32700 (Parse error), which is the correct JSON-RPC error code.