fix(client): put the probe's network failure on Error.cause, not data - #2703
Open
likalight wants to merge 2 commits into
Open
fix(client): put the probe's network failure on Error.cause, not data#2703likalight wants to merge 2 commits into
likalight wants to merge 2 commits into
Conversation
`SdkError`'s third constructor parameter is `data`, not `ErrorOptions`, so
`classifyNetworkError` passing `{ cause: error }` left `Error.cause`
undefined and stranded the underlying failure at `error.data.cause`.
Anything walking the standard `.cause` chain — loggers, error reporters,
`util.inspect` — stopped at the `SdkError` and never reached the
`TypeError: fetch failed`, nor the DNS/socket error beneath it that
actually names the failure.
Set `cause` on the instance with the same non-enumerable descriptor the
`Error` constructor would have produced.
This was the only site in the repo passing `{ cause }` into an
`SdkError` data slot.
Fixes modelcontextprotocol#2657
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: faba11c The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Fixes #2657.
The bug
SdkError's third constructor parameter isdata, notErrorOptions:So
classifyNetworkErrorpassing{ cause: error }as the third argumentnever reached
Error.cause. The underlying failure was stranded aterror.data.cause, where nothing walking the standard.causechain —loggers, error reporters,
util.inspect— will find it. Connecting to anunreachable host surfaced an
SdkErrorwhose.causewasundefined, withthe
TypeError: fetch failedand the DNS error that actually names theproblem both invisible to normal error handling.
The fix
Set
causeon the instance with the same non-enumerable descriptor theErrorconstructor would have produced.I grepped the repo:
probeClassifier.ts:314was the only site passing{ cause }into anSdkErrordata slot, so this is self-contained.One thing worth your call
test/client/probeAuthSeam.test.tshad an assertion pinning the oldbehaviour:
I updated it to assert
.causeinstead, on the reading that it was codifyingthe bug rather than a contract you intend to keep. If
data.causeisload-bearing for downstream consumers, say so and I'll set both — the
one-line alternative is to keep passing
{ cause: error }asdatainaddition to setting the real
cause. Happy to go either way.Verification
probeClassifier.test.tsasserting the fullchain resolves (
SdkError→TypeError: fetch failed→ENOTFOUND).Verified it fails without the source change:
AssertionError: expected undefined to be TypeError: fetch failedpackages/client: 805/805 tests passtsc --noEmit: cleanprettier --check: clean on all touched filesNote:
pnpm lint:allfails on this branch, but it fails identically on aclean checkout of
main— async:snippetsdocs drift unrelated to thischange.