Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ public HTTPRestResponse getTask(ServerCallContext context, String tenant, String
return createSuccessResponse(200, io.a2a.grpc.Task.newBuilder(ProtoUtils.ToProto.task(task)));
}
throw new TaskNotFoundError();
} catch (IllegalArgumentException e) {
return createErrorResponse(new InvalidParamsError(e.getMessage()));
} catch (A2AError e) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Catching the generic IllegalArgumentException is a bit risky here. While it correctly handles the invalid historyLength case from TaskQueryParams, it could also catch IllegalArgumentException thrown from other parts of the try block (e.g., a bug in an implementation of requestHandler.onGetTask). Such cases would indicate a server-side issue and should result in a 500 error, but would be incorrectly reported as a 422 client error.

To make this more robust, you could check the exception message to ensure you're only handling the specific error you expect. This avoids masking potential server-side bugs.

        } catch (IllegalArgumentException e) {
            if ("Invalid history length".equals(e.getMessage())) {
                return createErrorResponse(new InvalidParamsError(e.getMessage()));
            }
            throw e;
        }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. I agree with the concern about catching IllegalArgumentException too broadly.

I updated the implementation to scope the IllegalArgumentException handling to only the TaskQueryParams construction path, so only parameter-validation failures map to InvalidParamsError (422). Exceptions from downstream logic (e.g., requestHandler.onGetTask) are no longer reclassified as client errors.

Updated in commit 758f24e on this PR branch.

return createErrorResponse(e);
} catch (Throwable throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ public void testGetTaskNotFound() {
Assertions.assertTrue(response.getBody().contains("TaskNotFoundError"));
}

@Test
public void testGetTaskNegativeHistoryLengthReturns422() {
RestHandler handler = new RestHandler(CARD, requestHandler, internalExecutor);

RestHandler.HTTPRestResponse response = handler.getTask(callContext, "", MINIMAL_TASK.id(), -1);

Assertions.assertEquals(422, response.getStatusCode());
Assertions.assertEquals("application/json", response.getContentType());
Assertions.assertTrue(response.getBody().contains("InvalidParamsError"));
}

@Test
public void testListTasksStatusWireString() {
RestHandler handler = new RestHandler(CARD, requestHandler, internalExecutor);
Expand Down
Loading