Skip to content

fix(core): restore structured __repr__ on A2A exceptions - #1348

Open
cchinchilla-dev wants to merge 1 commit into
a2aproject:mainfrom
cchinchilla-dev:fix/restore-error-repr
Open

cchinchilla-dev wants to merge 1 commit into
a2aproject:mainfrom
cchinchilla-dev:fix/restore-error-repr

Conversation

@cchinchilla-dev

Copy link
Copy Markdown
Contributor

Description

Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Follow the CONTRIBUTING Guide.
  • Make your Pull Request title in the https://www.conventionalcommits.org/ specification.
    • Important Prefixes for release-please:
      • fix: which represents bug fixes, and correlates to a SemVer patch.
      • feat: represents a new feature, and correlates to a SemVer minor.
      • feat!:, or fix!:, refactor!:, etc., which represent a breaking change (indicated by the !) and will result in a SemVer major.
  • Ensure the tests and linter pass (Run bash scripts/format.sh from the repository root to format)
  • Appropriate docs were updated (if necessary)

Fixes #1347 🦕

Problem

#683 added __repr__ methods to the client exception classes (#679). The client error refactor in #761 replaced those classes with the A2AError-based hierarchy, and the __repr__ methods were not carried over. Both domain and client errors now fall back to the default Exception.__repr__, which only wraps str() output and loses structured attributes:

>>> repr(AgentCardResolutionError('Failed to fetch agent card', status_code=404))
"AgentCardResolutionError('Failed to fetch agent card')"  # Loses status_code

>>> repr(InvalidParamsError('Invalid field', data={'field': 'id'}))
"InvalidParamsError('Invalid field')"  # Loses data

Fix

Added __repr__ back, following the same pattern as #683:

A2AError (src/a2a/utils/errors.py): Exposes message and data as keyword arguments. All domain errors (TaskNotFoundError, InvalidParamsError, ...) and client errors (A2AClientError, A2AClientTimeoutError) inherit it.

>>> repr(InvalidParamsError('Invalid field', data={'field': 'id'}))
"InvalidParamsError(message='Invalid field', data={'field': 'id'})"

AgentCardResolutionError (src/a2a/client/errors.py): Exposes status_code, as A2AClientHTTPError did in #683.

>>> repr(AgentCardResolutionError('Failed to fetch agent card', status_code=404))
"AgentCardResolutionError(status_code=404, message='Failed to fetch agent card')"

This change does not alter traceback formatting, __str__ output, exception hierarchy, catching behavior, or any existing error handling logic. It is purely additive and intended to improve debuggability via repr() in REPLs, logs, and structured logging contexts.

Test

Tests were added to the existing suite at tests/client/test_errors.py, and to a new tests/utils/test_a2a_errors.py for A2AError and domain errors (test_errors.py is already taken by the client suite), keeping the same structure and conventions already in place.

No existing test was modified or removed, all additions are purely additive. Happy to adapt the test approach based on maintainer feedback.

@cchinchilla-dev
cchinchilla-dev requested a review from a team as a code owner October 16, 2026 19:33
@github-actions

Copy link
Copy Markdown

🧪 Code Coverage (vs main)

⬇️ Download Full Report

No coverage changes.

Generated by coverage-comment.yml

This branch has not been deployed

No deployments
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]: A2A exceptions lost their structured __repr__ after the client error refactor (#761)

1 participant