Skip to content

Commit 05aaff6

Browse files
fix(compat): return -32602 for invalid v0.3 JSON-RPC params (a2aproject#1419)
## Problem The v0.3 JSON-RPC adapter returned `-32600` when params failed validation. v0.3.26 returned `-32602` here. ## Fix Return `InvalidParamsError` instead of `InvalidRequestError`. ## Tests `test_invalid_params_v03_compat` fails on main. 2520 passed. Fixes a2aproject#1417 --------- Co-authored-by: Mateusz Iwaniuk <45974414+Iwaniukooo11@users.noreply.github.com>
1 parent f666ba3 commit 05aaff6

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

‎src/a2a/compat/v0_3/jsonrpc_adapter.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
InternalError as CoreInternalError,
3232
)
3333
from a2a.server.jsonrpc_models import (
34-
InvalidRequestError as CoreInvalidRequestError,
34+
InvalidParamsError as CoreInvalidParamsError,
3535
)
3636
from a2a.server.jsonrpc_models import (
3737
JSONRPCError as CoreJSONRPCError,
@@ -128,7 +128,7 @@ async def handle_request(
128128

129129
return self._generate_error_response(
130130
request_id,
131-
CoreInvalidRequestError(data=str(e)),
131+
CoreInvalidParamsError(data=str(e)),
132132
)
133133

134134
call_context = self._context_builder.build(request)

‎tests/compat/v0_3/test_jsonrpc_app_compat.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,27 @@ def test_get_task_not_found_v03_compat(
205205
assert data['error']['message'] == 'Task not found'
206206

207207

208+
def test_invalid_params_v03_compat(
209+
client: TestClient, mock_handler: AsyncMock
210+
) -> None:
211+
# The JSON-RPC envelope is valid but the params are not: a v0.3 Message
212+
# requires `parts`, so validating params fails and must return -32602.
213+
request_payload = {
214+
'jsonrpc': '2.0',
215+
'id': '7',
216+
'method': 'message/send',
217+
'params': {'message': {'messageId': 'req', 'role': 'user'}},
218+
}
219+
220+
response = client.post('/', json=request_payload)
221+
assert response.status_code == 200
222+
data = response.json()
223+
224+
assert data['id'] == '7'
225+
assert data['error']['code'] == -32602
226+
mock_handler.on_message_send.assert_not_called()
227+
228+
208229
@pytest.mark.parametrize(
209230
('error', 'expected_code'),
210231
[

0 commit comments

Comments
 (0)