Repository navigation
fix(compat-0.3): return InvalidParamsError for invalid SendMessage params - #1337
Merged
Merged
Conversation
…rams A v0.3 SendMessage with no messageId or with empty parts makes a message record throw IllegalArgumentException: the v1.0 Message during the v0.3 to v1.0 conversion, or Message_v0_3 when REST and gRPC read the request. Only JSONRPCHandler_v0_3.onMessageSend mapped it to invalid params, so REST, gRPC and JSON-RPC message/stream reported an internal error. Convert the exception where it is raised, as v1.0 does in ProtoUtils.FromProto.convert(): Convert_v0_3_To10RequestHandler now throws InvalidParamsError when converting the params, and ProtoUtils_v0_3.FromProto.messageSendParams throws InvalidParamsError_v0_3. Fixes a2aproject#1336
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
CONTRIBUTINGGuide.fix:which represents bug fixes, and correlates to a SemVer patch.feat:represents a new feature, and correlates to a SemVer minor.feat!:, orfix!:,refactor!:, etc., which represent a breaking change (indicated by the!) and will result in a SemVer major.Fixes #1336 🦕
Problem
In the v0.3 compatibility layer, a
SendMessagewhose message has nomessageIdor an emptypartslist is only rejected withInvalidParamsErrorby JSON-RPCmessage/send. REST and gRPC report it as an internal error, and so does JSON-RPCmessage/streamfor a missingmessageId:The checks throw
IllegalArgumentExceptionfrom the v1.0Messageduring the v0.3 to v1.0 conversion (messageId) and fromMessage_v0_3inProtoUtils_v0_3.FromProto.message(parts). OnlyJSONRPCHandler_v0_3.onMessageSendmaps it toInvalidParamsError_v0_3; every other path reportsInternalError_v0_3. This is what the v0.3 TCK reports for REST and gRPC in thetck-test-0-3job (test_missing_required_message_fieldsandtest_empty_arrays).Fix
The exception is now converted where it is raised, the same way v1.0 does in
ProtoUtils.FromProto.convert():Convert_v0_3_To10RequestHandler:onMessageSendandonMessageSendStreamconvert the params through a small helper that turns theIllegalArgumentExceptionfromMessageSendParamsMapper_v0_3.toV10intoInvalidParamsError.ErrorConverter_v0_3already maps it toInvalidParamsError_v0_3on every transport.ProtoUtils_v0_3.FromProto.messageSendParams: throwsInvalidParamsError_v0_3for the same exception, which the REST and gRPC handlers already report as invalid params.The handlers are unchanged. Clients now get
InvalidParamsError_v0_3with the original message (Parameter 'messageId' may not be null,Parts cannot be empty): HTTP 422 for RESTmessage:send, anInvalidParamsError_v0_3event in themessage:streamSSE stream,INVALID_ARGUMENTover gRPC and -32602 over JSON-RPC. Exceptions raised by the backend or while writing the response still go throughInternalError_v0_3.Test
Tests were added to the existing handler suites:
RestHandler_v0_3_Test:testSendMessageMissingMessageId,testSendMessageEmptyPartsandtestSendStreamingMessageMissingMessageId.GrpcHandler_v0_3_Test:testOnMessageMissingMessageId,testOnMessageEmptyPartsandtestOnMessageStreamMissingMessageId, which also check theInvalidParamsErrordescription.JSONRPCHandler_v0_3_Test:testOnMessageStreamMissingMessageId.The seven tests fail on
main, where they getInternalError_v0_3, and pass with the fix. No existing test was modified or removed. Thecompat-0.3spec-grpc, server-conversion, transport and reference modules build and pass their suites, and with the fix the v0.3 TCK (0.3.0.beta6,--category all --transports jsonrpc,grpc,rest, as in CI) runs againstcompat-0.3/tckwith no failures.Happy to adapt the test approach based on maintainer feedback.