Skip to content

feat: implement the new rest error handling#282

Merged
yarolegovich merged 2 commits intomainfrom
yarolegovich/transcode-friendly-err-fmt
Mar 16, 2026
Merged

feat: implement the new rest error handling#282
yarolegovich merged 2 commits intomainfrom
yarolegovich/transcode-friendly-err-fmt

Conversation

@yarolegovich
Copy link
Copy Markdown
Member

changes to the REST error format based on a2aproject/A2A#1600 spec changes

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 overhauls the REST API's error handling to conform to the Google RPC Status specification (AIP-193). This change aims to provide a more consistent, structured, and detailed error reporting mechanism for API consumers, improving interoperability and clarity when encountering issues. The update affects how errors are generated on the server and how they are expected to be parsed by clients, moving away from a less standardized problem details format.

Highlights

  • REST Error Format Migration: The REST error handling has been migrated from the RFC 7807 Problem Details format to the Google RPC Status format (AIP-193), standardizing error responses.
  • Content-Type Header Update: The Content-Type header for error responses has been changed from application/problem+json to application/json across the server and tests.
  • New Error Structures and Conversion Logic: New Go structs (ErrorInfo, StatusError, Error) were introduced to represent the Google RPC Status format, and the ToA2AError and ToRESTError functions were rewritten to handle conversions between internal errors and the new REST error structure, including support for non-string error details.
  • Enhanced Error Details: The internal errorDetails structure and errToDetails map were updated to include gRPC status and reason fields, providing more granular error classification.
Changelog
  • a2asrv/rest.go
    • Updated the Content-Type header for error responses from application/problem+json to application/json.
    • Modified the WriteHeader call to use errResp.HTTPStatus() instead of errResp.Status.
  • a2asrv/rest_test.go
    • Adjusted the expected Content-Type header in error response tests from application/problem+json to application/json.
  • internal/rest/rest.go
    • Added maps and strings imports.
    • Introduced new constants errorInfoType and errorDomain.
    • Defined new structs ErrorInfo and StatusError to represent parts of the Google RPC Status format.
    • Redefined the Error struct to encapsulate StatusError and an internal httpStatus.
    • Added an HTTPStatus() method to the Error struct.
    • Modified the errorDetails struct to include httpStatus, grpcStatus, and reason fields, replacing status, uri, and title.
    • Updated the errToDetails map with new httpStatus, grpcStatus, and reason values.
    • Rewrote ToA2AError to parse the new Google RPC Status error format, extract ErrorInfo details, and handle additional metadata.
    • Rewrote ToRESTError to construct error responses in the Google RPC Status format, including ErrorInfo and handling a2a.Error details.
  • internal/rest/rest_test.go
    • Added encoding/json and fmt imports.
    • Introduced helper functions makeStatusBody and mustJSON for creating test response bodies in the new format.
    • Updated TestError_ToA2AError test cases to use the new Google RPC Status format for responseBody and changed wantDetail to wantMessage.
    • Modified assertions in TestError_ToA2AError to check for errors.Is and strings.Contains with wantMessage.
    • Updated TestToRESTError test cases to expect wantHTTPStatus, wantGRPCStatus, and wantReason.
    • Modified assertions in TestToRESTError to validate the new Error struct fields and ErrorInfo details.
    • Added TestToRESTError_RoundTrip to verify conversion fidelity between ToRESTError and ToA2AError.
    • Added TestToRESTError_NonStringDetails to ensure non-string error details are correctly handled and preserved during conversion.
Activity
  • The pull request was opened by yarolegovich with the title 'feat: implement the new rest error handling'.
  • The author specified that the changes align with the REST error format based on the spec changes in https://github.com/a2aproject/A2A/pull/1600.
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.

Copy link
Copy Markdown
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 refactors the REST error handling to align with the Google RPC status error format, moving away from RFC 7807 problem+json. The implementation is thorough, with corresponding updates to error creation, parsing, and comprehensive test adjustments. The addition of round-trip tests is a commendable approach to ensure the serialization and deserialization logic is robust. I have one high-severity finding regarding the use of t.Parallel() in the new tests that should be addressed.

@yarolegovich yarolegovich merged commit a3bda30 into main Mar 16, 2026
4 checks passed
@yarolegovich yarolegovich deleted the yarolegovich/transcode-friendly-err-fmt branch March 16, 2026 16:27
yarolegovich pushed a commit that referenced this pull request Mar 17, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.0.0](v1.0.0-alpha.3...v1.0.0)
(2026-03-17)


### Features

* implement the new rest error handling
([#282](#282))
([a3bda30](a3bda30))
* use v2 suffix for module ID and provide compat support
([#270](#270))
([dd1b6ba](dd1b6ba)),
closes [#250](#250)


### Bug Fixes

* a2asrv jsonrpc Content-Type
([#265](#265))
([2568a46](2568a46))
* bugs before going from alpha
([#279](#279))
([b1f055c](b1f055c))
* GetTaskRequest nil pointer assignment check
([#258](#258))
([440bb79](440bb79))
* inject headers into service params
([#277](#277))
([d33f3bd](d33f3bd)),
closes [#275](#275)
* propagate cancelation signal using task store
([#272](#272))
([5e1d462](5e1d462)),
closes [#245](#245)
* regenerate spec and fix returnImmediately
([#284](#284))
([2eee0b9](2eee0b9))
* task modified after save
([#266](#266))
([c15febe](c15febe))
* taskupdater result mutable
([#274](#274))
([6038d92](6038d92))
* update pushsender
([#256](#256))
([5f7a594](5f7a594))
* use enum values as in the spec
([#261](#261))
([eb98981](eb98981)),
closes [#251](#251)


### Documentation

* **a2asrv:** add Example_* test functions for pkg.go.dev documentation
([#262](#262))
([7888e37](7888e37))
* add example tests a2a
([#240](#240))
([4fe08a9](4fe08a9))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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.

2 participants