util: `SuppressedError` should print `error`/`suppressed` properties during inspection
Nessuno ha ancora preso questa issue.
- Lingua principale
- JavaScript
- Stelle
- 122k
- Fork
- 37.3k
- Merge medio
- 4g 2h
- PR unite (30g)
- 283
Descrizione
What is the problem this feature will solve?
When a SuppressedError is thrown (e.g. from disposal errors during a using/await using block) and inspected via util.inspect() / console.log(), then the actual underlying errors (error and suppressed properties) are not shown:
class Resource {
[Symbol.dispose]() {
throw new Error('error during dispose');
}
}
function test() {
using res = new Resource();
throw new Error('error during execution');
}
test();
Current output (Node v26.8.2):
SuppressedError: An error was suppressed during disposal.
at test (REPL10:3:3)
Both those errors are essential for debugging.
This has the exact same shape as two problems Node already solved for other "container" errors:
AggregateError.errors was silently swallowed during inspection — fixed in #43646 (tracked in #43645).
Error.cause was silently swallowed during inspection — fixed in #41002 (tracked in #40859).
SuppressedError.error / SuppressedError.suppressed fall into the same category and currently have no equivalent handling in formatError() (lib/internal/util/inspect.js).
What is the feature you are proposing to solve the problem?
Extend formatError() so that, similar to how cause and errors are already special-cased, the non-enumerable error and suppressed properties of a SuppressedError are always included in the inspected output (recursively, since a SuppressedError can itself wrap another SuppressedError when multiple disposals fail).
Desired output, roughly matching what the cause-chain rendering already does:
SuppressedError: An error was suppressed during disposal.
at test (…)
... {
[error]: Error: error during dispose
at Resource.[Symbol.dispose] (…)
...,
[suppressed]: Error: error during execution
at test (…)
...
}
What alternatives have you considered?
- Manually logging e.error and e.suppressed in application code — works, but requires every catch block to know it might be dealing with a SuppressedError.
- A userland [util.inspect.custom] patch on SuppressedError.prototype — works.
I believe a better out-of-the-box experience is required, rather than user-land patches. Workarounds shouldn't be necessary for a built-in error type tied to a TC39-standardized language feature
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia in lib/internal/util/inspect.js, in formatError(), confrontando la gestione speciale esistente per cause ed errors. Estendi l’ispezione in modo che SuppressedError.error e SuppressedError.suppressed vengano visualizzati ricorsivamente, quindi verifica che util.inspect() e console.log() producano l’output annidato richiesto per gli errori di rilascio delle risorse.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript
- Ambito
- tooling
- Tipo di issue
- Funzionalità
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Attiva
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 78/100