Skip to content

fix: keep the stack of fetch errors when __filename is undefined - #6116

Open
MIbtehajNasar wants to merge 1 commit into
nodejs:mainfrom
MIbtehajNasar:fix-6115-bundled-fetch-stack
Open

MIbtehajNasar wants to merge 1 commit into
nodejs:mainfrom
MIbtehajNasar:fix-6115-bundled-fetch-stack

Conversation

@MIbtehajNasar

Copy link
Copy Markdown

This relates to...

Fixes #6115

Rationale

When __filename is undefined, which is the case for the copy bundled into Node.js, the fetch wrapper calls Error.captureStackTrace(err, module.exports.fetch) from the .catch callback. fetch is no longer on the stack at that point, so V8 records no frames and every rejected error has an empty stack (just TypeError: fetch failed). #4812 meant this branch to fall back to Error.captureStackTrace(err), but it passed module.exports.fetch as the second argument.

Changes

Features

N/A

Bug Fixes

  • index-fetch.js and index.js: drop the constructorOpt argument so the stack keeps the callback frame and the caller's async frames:
TypeError: fetch failed
    at .../index-fetch.js:40:13
    at async caller (.../repro.cjs:8:34)
  • Test in test/fetch/client-error-stack-trace.js that loads index-fetch.js in a module wrapper without __filename, as Node.js does, and checks that the caller appears in the stack. It fails on main.

Breaking Changes and Deprecations

N/A

Status

When __filename is undefined (as in Node.js's bundled copy), the fetch
wrapper called Error.captureStackTrace(err, module.exports.fetch) from
the .catch callback. fetch is no longer on the stack there, so V8
recorded no frames and every error had an empty stack. Drop the
constructorOpt, as nodejs#4812 intended.

Fixes nodejs#6115

This branch has not been deployed

No deployments
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.

fetch: errors from Node's bundled fetch have an empty stack

1 participant