Skip to content

Conversation

@ehsavoie
Copy link
Collaborator

  • When the json is converted to an Object, internal validation may throw IllegalArgumentException which should be converted in a proper error.

This fixes issue#512

Fixes #512 🦕

@ehsavoie ehsavoie requested a review from jmesnil December 12, 2025 10:14
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ehsavoie, 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 significantly enhances the robustness of the server's JSON-RPC API by implementing more precise and informative error handling for invalid incoming messages. Previously, malformed or structurally incorrect JSON could lead to a generic InternalServerError. The changes introduce mechanisms to catch specific JSON parsing and protocol buffer conversion exceptions, translating them into appropriate JSON-RPC error responses like InvalidParamsError or JSONParseError. This provides clearer feedback to clients and streamlines debugging by pinpointing the exact nature of the invalid request.

Highlights

  • Improved Error Handling: The server now returns specific JSON-RPC errors (e.g., Invalid Params, Parse Error) instead of a generic Internal Server Error when processing malformed or invalid JSON messages. This includes handling JsonSyntaxException for malformed JSON and JsonProcessingException for invalid JSON structure or types.
  • Centralized JSON Parsing Refinement: The JSONRPCUtils class has been refactored to provide more granular and intelligent conversion of InvalidProtocolBufferException into appropriate JsonProcessingException subtypes, such as InvalidParamsJsonMappingException or JsonMappingException, based on the specific error details.
  • Request ID Preservation in Errors: The request ID from the incoming JSON-RPC message is now correctly extracted and included in the generated error responses, even in cases where the ID itself might be malformed or missing, improving traceability.
  • Internal Validation Mapping: Internal IllegalArgumentException instances that occur during the conversion from Protocol Buffer objects to A2A specification objects are now caught and mapped to a JSON-RPC InvalidParamsError, preventing these internal validation failures from escalating to InternalServerError.
  • Enhanced Test Coverage: New and updated unit tests have been added to comprehensively validate the improved error handling logic across various invalid JSON scenarios, including missing fields, unknown fields, and the correct preservation of request IDs in error responses.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@ehsavoie ehsavoie requested a review from kabir December 12, 2025 10:14
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses the issue of converting IllegalArgumentException into a proper JSON-RPC error, which prevents internal server errors when invalid messages are sent. The changes in JSONRPCUtils significantly improve error handling and reporting for protobuf parsing failures, and the new try-catch blocks in ProtoUtils correctly handle validation exceptions from the mappers. I have identified a critical issue in the new tests that will cause them to fail, along with a couple of opportunities for code improvement and consistency.

…rError

* When the json is converted to an Object, internal validation may throw
  IllegalArgumentException which should be converted in a proper error.

This fixes issue#512

Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
@ehsavoie
Copy link
Collaborator Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses the issue of converting internal validation exceptions into proper JSON-RPC errors. The changes in JSONRPCUtils to provide more detailed error messages from InvalidProtocolBufferException are a significant improvement. The addition of new unit tests to cover these error-handling scenarios is also commendable. The refactoring in ProtoUtils to consistently handle IllegalArgumentException from mappers is a good enhancement for robustness. Overall, the changes improve error handling and make the server's responses more informative for clients in case of invalid requests. I have one suggestion for improving consistency in the new error conversion logic.

@ehsavoie ehsavoie merged commit ed48c79 into a2aproject:main Dec 12, 2025
11 checks passed
@ehsavoie ehsavoie deleted the issue_512 branch December 19, 2025 16:23
kabir pushed a commit to kabir/a2a-java that referenced this pull request Dec 23, 2025
…rError (a2aproject#536)

* When the json is converted to an Object, internal validation may throw
IllegalArgumentException which should be converted in a proper error.

This fixes issue#512

Fixes a2aproject#512 🦕

Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: [spec-1.0] Sending an invalid message to the server raises an InternalServerError

2 participants