fix(core): forward cause from the SdkError data slot to Error.cause - #2683
Open
xiangnuans wants to merge 1 commit into
Open
fix(core): forward cause from the SdkError data slot to Error.cause#2683xiangnuans wants to merge 1 commit into
cause from the SdkError data slot to Error.cause#2683xiangnuans wants to merge 1 commit into
Conversation
`classifyNetworkError` (and other call sites) pass an underlying error to
`SdkError` as `{ cause }` in the `data` slot, but the constructor called
`super(message)` with no options — so `Error.cause` stayed `undefined` and
the standard cause chain broke. Loggers/trackers that walk `.cause` (pino's
default serializer, Sentry) stopped at the `SdkError` and lost the root
network error, so `ENOTFOUND` / `ECONNREFUSED` / `ETIMEDOUT` all rendered
identically as "fetch failed".
Forward `cause` to `super()` when `data` carries one, while still retaining
the full object on `this.data`. This covers every call site that hands
`{ cause }` to the data slot (the issue's preferred fix), and leaves
`SdkHttpError`'s status/statusText payload untouched.
Closes modelcontextprotocol#2657
|
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
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.
Closes #2657
Problem
classifyNetworkError(and other call sites) construct anSdkErrorwith the underlying error in thedataslot as{ cause }:But
SdkError's third parameter isdata, notErrorOptions, and the constructor calledsuper(message)with no options — soError.causestayedundefinedand the{ cause }object just landed onthis.data. Anything walking the standard.causechain (pino's defaulterrserializer, Sentry's exception linking) stops at theSdkError, so the root network error is lost:Fix
Per the issue's preferred option 1 (safer, since the mismatch is silent at every call site),
SdkErrornow forwardscausetosuper()when itsdatacarries one, so the chain is unbroken:dataobject is still retained onthis.data(backwards compatible —.data.causekeeps working).SdkHttpError's{ status, statusText }payload has nocause, so it is unaffected.{ cause }to thedataslot.Tests
Added
packages/core-internal/test/errors/sdkErrorCause.test.ts:causefrom the data slot reachesError.cause(fails onmainwithout the fix).datacause/ nodata→.causestaysundefinedSdkHttpErrorstatus payload is not treated as a causepnpm --filter @modelcontextprotocol/core-internal test(1452 passing),typecheck, andlintall clean.