Skip to content

Commit 2c152c0

Browse files
authored
fix: Add __str__ and __repr__ methods to ServerError (#489)
Add `__str__` and `__repr__` methods to `ServerError` and fix the misleading comment in the constructor
1 parent de376d0 commit 2c152c0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/a2a/utils/errors.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ def __init__(
6666
6767
Args:
6868
error: The specific A2A or JSON-RPC error model instance.
69-
If None, an `InternalError` will be used when formatting the response.
7069
"""
7170
self.error = error
71+
72+
def __str__(self) -> str:
73+
"""Returns a readable representation of the internal Pydantic error."""
74+
if self.error is None:
75+
return 'None'
76+
if self.error.message is None:
77+
return self.error.__class__.__name__
78+
return self.error.message
79+
80+
def __repr__(self) -> str:
81+
"""Returns an unambiguous representation for developers showing how the ServerError was constructed with the internal Pydantic error."""
82+
return f'{self.__class__.__name__}({self.error!r})'

0 commit comments

Comments
 (0)