Skip to content

Classify InvalidData dispatch exceptions correctly over ice#4559

Merged
pepone merged 3 commits intoicerpc:mainfrom
pepone:fix/ice-dispatch-invalid-data-classification
Apr 27, 2026
Merged

Classify InvalidData dispatch exceptions correctly over ice#4559
pepone merged 3 commits intoicerpc:mainfrom
pepone:fix/ice-dispatch-invalid-data-classification

Conversation

@pepone
Copy link
Copy Markdown
Member

@pepone pepone commented Apr 27, 2026

Fixes #4463

Copilot AI review requested due to automatic review settings April 27, 2026 13:27
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes status-code classification for exceptions thrown during Slice-over-Ice dispatch so malformed client requests are reported as InvalidData (instead of being lumped into InternalError), aligning behavior with the icerpc protocol while preserving canonical Ice wire-compatibility.

Changes:

  • Update the ice dispatch exception classification to map InvalidDataException and IceRpcException(TruncatedData) to StatusCode.InvalidData.
  • Add a parameterized regression test that asserts the classified StatusCode observed by the client for these exception kinds.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/IceRpc/Internal/IceProtocolConnection.cs Classifies dispatcher-thrown InvalidDataException and TruncatedData as InvalidData for Ice replies.
tests/IceRpc.Tests/IceProtocolConnectionTests.cs Adds a regression test verifying the new exception → status-code mapping.

[TestCase("InvalidData", StatusCode.InvalidData)]
[TestCase("TruncatedData", StatusCode.InvalidData)]
[TestCase("Other", StatusCode.InternalError)]
public async Task Thrown_dispatch_exception_is_classified(string exceptionKind, StatusCode expectedStatusCode)
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

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

The test name Thrown_dispatch_exception_is_classified is misleading: the dispatcher is throwing non-DispatchException exceptions (e.g., InvalidDataException, IceRpcException) and the test verifies how they are mapped into a DispatchException status code. Consider renaming the test to reflect that it covers classification of exceptions thrown by the dispatcher (not a thrown DispatchException).

Suggested change
public async Task Thrown_dispatch_exception_is_classified(string exceptionKind, StatusCode expectedStatusCode)
public async Task Thrown_dispatcher_exception_is_classified(string exceptionKind, StatusCode expectedStatusCode)

Copilot uses AI. Check for mistakes.
The icerpc dispatcher catch block already maps InvalidDataException to
StatusCode.InvalidData. The ice dispatcher catch block had no such
switch — every non-DispatchException ended up as InternalError, so a
malformed Slice-over-ice request was reported to the client as a
server fault and inflated server-error rates on dashboards that split
client- vs server-side faults by status code.

Map InvalidDataException to StatusCode.InvalidData. The ice encoder's
existing case at IceProtocolConnection.cs:896-898 emits a real
ReplyStatus.InvalidData on the wire, so canonical-Ice peers see the
right status.

Add a parameterized regression test asserting that a thrown
InvalidDataException surfaces as StatusCode.InvalidData and an
unrelated thrown exception still becomes StatusCode.InternalError.
@pepone pepone force-pushed the fix/ice-dispatch-invalid-data-classification branch from 8607768 to c18a047 Compare April 27, 2026 13:36
Per review, "dispatch exception" reads like the DispatchException
type. The test exercises non-DispatchException exceptions thrown
by the dispatcher and verifies how the catch block classifies them
into a DispatchException's status code, so "dispatcher exception"
is more accurate.
Copy link
Copy Markdown
Member

@InsertCreativityHere InsertCreativityHere left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Just need to fix the other protocol test which was apparently expecting an InternalError.

This test case codified the pre-fix behavior (ice dispatcher mapping
InvalidDataException to InternalError). With the catch-block change in
this PR, both protocols now classify thrown InvalidDataException as
StatusCode.InvalidData, so update the expectation to match.
@pepone pepone merged commit 1b4dce6 into icerpc:main Apr 27, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Audit-Low] Slice request-decode and idempotency-validation failures…

4 participants