Repository navigation
Commit 79a6f45
fix(core): restore structured __repr__ on A2A exceptions (a2aproject#1348)
# 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:
- [x] Follow the [`CONTRIBUTING`
Guide](https://github.com/a2aproject/a2a-python/blob/main/CONTRIBUTING.md).
- [x] Make your Pull Request title in the
<https://www.conventionalcommits.org/> specification.
- Important Prefixes for
[release-please](https://github.com/googleapis/release-please):
- `fix:` which represents bug fixes, and correlates to a
[SemVer](https://semver.org/) 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.
- [x] Ensure the tests and linter pass (Run `bash scripts/format.sh`
from the repository root to format)
- [x] Appropriate docs were updated (if necessary)
Fixes a2aproject#1347 🦕
## Problem
a2aproject#683 added `__repr__` methods to the client exception classes (a2aproject#679).
The client error refactor in a2aproject#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:
```python
>>> 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 a2aproject#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.
```python
>>> 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 a2aproject#683.
```python
>>> 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.
Co-authored-by: mykytanetipa <mykytanetipa@google.com>1 parent 91929cd commit 79a6f45
4 files changed
Lines changed: 96 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
17 | 25 | | |
18 | 26 | | |
19 | 27 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
30 | 38 | | |
31 | 39 | | |
32 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
4 | 8 | | |
5 | 9 | | |
6 | 10 | | |
| |||
23 | 27 | | |
24 | 28 | | |
25 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
0 commit comments