Skip to content

internal/jsonrpc2: test WireError.Is and fix nil target panic#1079

Draft
aha-jansen wants to merge 1 commit into
modelcontextprotocol:mainfrom
aha-jansen:test/wireerror-is-coverage
Draft

internal/jsonrpc2: test WireError.Is and fix nil target panic#1079
aha-jansen wants to merge 1 commit into
modelcontextprotocol:mainfrom
aha-jansen:test/wireerror-is-coverage

Conversation

@aha-jansen

Copy link
Copy Markdown

Problem

WireError.Is backs errors.Is checks used across the SDK against sentinels such as ErrMethodNotFound, ErrRejected, and ErrClientClosing, but had no direct test. Add a table-driven test for it.

While doing so, errors.Is(err, (*WireError)(nil)) was found to panic on a nil pointer dereference, because Is read w.Code without a nil check. Guard against a nil *WireError target so the comparison returns false.

errors.Is(err, (*WireError)(nil)) // panic: nil pointer dereference

Approach

Is read w.Code after a successful type assertion without checking whether w itself was nil. The fix guards against a nil *WireError target so the comparison returns false instead of panicking.

Test plan

  • go test ./internal/jsonrpc2/ passes.
  • The new typed nil WireError case panics without the one-line fix and passes with it, confirming the test exercises the guarded path.

WireError.Is backs errors.Is checks used across the SDK against sentinels
such as ErrMethodNotFound, ErrRejected, and ErrClientClosing, but had no
direct test. Add a table-driven test for it.

While doing so, errors.Is(err, (*WireError)(nil)) was found to panic on a
nil pointer dereference, because Is read w.Code without a nil check. Guard
against a nil *WireError target so the comparison returns false.
@aha-jansen aha-jansen force-pushed the test/wireerror-is-coverage branch from 5e87684 to 1cb0495 Compare July 13, 2026 12:09
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.

1 participant