Skip to content

Commit 6aba874

Browse files
committed
feat: Add custom error messages to
1 parent a38d438 commit 6aba874

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/a2a/utils/errors.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
ContentTypeNotSupportedError,
55
InternalError,
66
InvalidAgentResponseError,
7-
InvalidParamsError,
7+
InvalidParamsError as InvalidParamsErrorType,
88
InvalidRequestError,
99
JSONParseError,
1010
JSONRPCError,
@@ -35,6 +35,14 @@ def __init__(
3535
super().__init__(f'Not Implemented operation Error: {message}')
3636

3737

38+
class InvalidParamsError(InvalidParamsErrorType):
39+
"""
40+
JSON-RPC error indicating invalid method parameter(s).
41+
"""
42+
43+
message: str = 'Invalid parameters'
44+
45+
3846
class ServerError(Exception):
3947
"""Wrapper exception for A2A or JSON-RPC errors originating from the server's logic.
4048

tests/utils/test_proto_utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,23 @@ def test_task_query_params_invalid_name(self):
137137
request = a2a_pb2.GetTaskRequest(name='invalid-name-format')
138138
with pytest.raises(ServerError) as exc_info:
139139
proto_utils.FromProto.task_query_params(request)
140+
140141
assert isinstance(exc_info.value.error, types.InvalidParamsError)
142+
assert (
143+
exc_info.value.error.message
144+
== 'invalid-name-format: invalid-name-format'
145+
)
146+
147+
def test_task_id_params_invalid_name(self):
148+
request = a2a_pb2.CancelTaskRequest(name='invalid-name-format')
149+
with pytest.raises(ServerError) as exc_info:
150+
proto_utils.FromProto.task_id_params(request)
151+
152+
assert isinstance(exc_info.value.error, types.InvalidParamsError)
153+
assert (
154+
exc_info.value.error.message
155+
== 'invalid-name-format: invalid-name-format'
156+
)
141157

142158

143159
class TestProtoUtils:

0 commit comments

Comments
 (0)