nodejs / nodejs/undici

fetch error loses stack context

Open
#2,331 17 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug fetch
Dominant language
JavaScript
Stars
7.7k
Forks
880
Avg merge
2d 16h
Merged PRs (30d)
68

Description

repro from #2328

without the Error.captureStackTrace in index.js:

NODE_V8_COVERAGE='./coverage/tmp' node test.mjs
/var/github/undici/lib/compat/dispatcher-weakref.js:25
    dispatcher.on('disconnect', () => {
               ^

TypeError: dispatcher.on is not a function
    at CompatFinalizer.register (/var/github/undici/lib/compat/dispatcher-weakref.js:25:16)
    at new Request (/var/github/undici/lib/fetch/request.js:391:26)
    at fetch (/var/github/undici/lib/fetch/index.js:136:21)
    at fetch (/var/github/undici/index.js:107:20)
    at file:///var/github/undici/test.mjs:5:7
    at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:308:24)
    at async loadESM (node:internal/process/esm_loader:42:7)
    at async handleMainPromise (node:internal/modules/run_main:66:12)

Node.js v20.6.1

with:

 NODE_V8_COVERAGE='./coverage/tmp' node test.mjs
/var/github/undici/index.js:110
        Error.captureStackTrace(err, this)
              ^

TypeError: dispatcher.on is not a function
    at fetch (/var/github/undici/index.js:110:15)
    at async file:///var/github/undici/test.mjs:5:1

Node.js v20.6.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Compare the stack traces in index.js with the failing path through lib/compat/dispatcher-weakref.js, fetch/request.js, and fetch/index.js. Reproduce the report with test.mjs and NODE_V8_COVERAGE, then ensure the resulting fetch error retains useful caller context without losing the original TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.