Commit 52f0c6a
feat: add __repr__ to client exception classes for debugging parity with server errors (#683)
# 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 #679 🦕
## Problem
Server-side exceptions (`ServerError`) implement `__repr__` for
developer-friendly debugging output, but client-side exceptions
(`A2AClientHTTPError`, `A2AClientJSONError`, `A2AClientTimeoutError`,
`A2AClientInvalidArgsError`, `A2AClientInvalidStateError`,
`A2AClientJSONRPCError`) do not. When these exceptions appear during
debugging, they show minimal information via the default
`Exception.__repr__`, which only wraps `str()` output and loses
structured attributes:
```python
>>> repr(A2AClientHTTPError(404, 'Not Found'))
"A2AClientHTTPError('HTTP Error 404: Not Found')" # Loses status_code as a distinct attribute
````
For `A2AClientJSONRPCError`, the situation is worse — `repr` flattens
the underlying `JSONRPCError` object into a single string, losing
structured access to the error code and data during inspection.
## Fix
Added `__repr__` methods to all client exception classes in
`src/a2a/client/errors.py`, following the same pattern already
established by `ServerError.__repr__` in `src/a2a/utils/errors.py`:
```python
>>> repr(A2AClientHTTPError(404, 'Not Found'))
"A2AClientHTTPError(status_code=404, message='Not Found')"
````
`A2AClientJSONError`, `A2AClientTimeoutError`,
`A2AClientInvalidArgsError`, `A2AClientInvalidStateError`: Expose
message as a `keyword` argument.
```python
>>> repr(A2AClientTimeoutError('Connection timed out after 30s'))
"A2AClientTimeoutError(message='Connection timed out after 30s')"
```
`A2AClientJSONRPCError`: Delegates to `repr()` of the inner
`JSONRPCError` object, preserving structured error code and data.
```python
>>> repr(A2AClientJSONRPCError(response))
"A2AClientJSONRPCError(JSONRPCError(code=-32600, message='Invalid Request', data=None))"
```
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 directly into the existing suite at
`tests/client/test_errors.py`, 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.
Release-As: 0.3.23
---------
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>1 parent 63c1e93 commit 52f0c6a
2 files changed
Lines changed: 101 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
24 | 32 | | |
25 | 33 | | |
26 | 34 | | |
| |||
34 | 42 | | |
35 | 43 | | |
36 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
37 | 49 | | |
38 | 50 | | |
39 | 51 | | |
| |||
47 | 59 | | |
48 | 60 | | |
49 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
50 | 66 | | |
51 | 67 | | |
52 | 68 | | |
| |||
60 | 76 | | |
61 | 77 | | |
62 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
63 | 83 | | |
64 | 84 | | |
65 | 85 | | |
| |||
73 | 93 | | |
74 | 94 | | |
75 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
76 | 100 | | |
77 | 101 | | |
78 | 102 | | |
| |||
85 | 109 | | |
86 | 110 | | |
87 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
6 | 13 | | |
7 | 14 | | |
8 | 15 | | |
| |||
35 | 42 | | |
36 | 43 | | |
37 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
38 | 53 | | |
39 | 54 | | |
40 | 55 | | |
| |||
81 | 96 | | |
82 | 97 | | |
83 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
84 | 106 | | |
85 | 107 | | |
86 | 108 | | |
| |||
108 | 130 | | |
109 | 131 | | |
110 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
111 | 184 | | |
112 | 185 | | |
113 | 186 | | |
| |||
0 commit comments