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

Aperta Adatta ai principianti
#6,115 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@MIbtehajNasar ci sta già lavorando.

Dal 29/10/2026.

  • #6116 di @MIbtehajNasar — aperta

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, node.js
Ambito
backend

Direzione di ricerca

Apri index-fetch.js e analizza il ramo di fallback usato quando __filename non è definito, insieme alla chiamata a Error.captureStackTrace descritta nell’issue. Rimuovi l’opzione del costruttore affinché V8 possa acquisire i frame dello stack disponibili, quindi verifica che gli errori del fetch integrato in Node includano i frame del chiamante, come mostrato nella riproduzione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug Description

Every error Node's built-in fetch rejects with has an empty stack: just the Name: message line, no frames. This started with #4812.

The cause is the fallback branch in index-fetch.js, taken when __filename is undefined, as in Node's bundled copy:

} else if (err && typeof err === 'object') {
  Error.captureStackTrace(err, module.exports.fetch)
}

This runs inside the .catch callback, where fetch is no longer on the stack. When V8 can't find the constructorOpt frame it records no frames, so the stack ends up empty. Dropping the second argument fixes it.

Reproducible By

// repro.mjs: uses Node's global fetch (undici from npm takes the other branch)
async function caller (signal) {
  await fetch('http://localhost:1', { signal })
}
await caller().catch(err => console.log(err.stack))
await caller(AbortSignal.abort(new Error('my reason'))).catch(err => console.log(err.stack))

Expected Behavior

Node 24.13.1 (undici 7.18.2):

TypeError: fetch failed
    at node:internal/deps/undici/undici:16416:13
    at async caller (file:///…/repro.mjs:2:3)
    at async file:///…/repro.mjs:4:1
Error: my reason
    at node:internal/deps/undici/undici:16416:13
    at async caller (file:///…/repro.mjs:2:3)
    at async file:///…/repro.mjs:5:1

Logs & Screenshots

Node 24.22.1 (undici 7.30.1) and 26.13.0 (undici 8.12.2):

TypeError: fetch failed
Error: my reason

Environment

macOS and Alpine Linux, both arm64. Affected: Node 24.22.1 and 26.13.0. The branch is unchanged on main.

Lingua principale
JavaScript
Stelle
7.7k
Fork
966
Merge medio
3g 8h
PR unite (30g)
56

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nodejs/undici

Tutte le issue di nodejs/undici

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.