nodejs / nodejs/node

Expose the "enhanced" stack trace from uncaught exceptions to the `uncaughtException` and `uncaughtExceptionMonitor` handlers on `process`

Aperta
#55,838 9 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

events feature request
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?

In my app, I have a logging system which writes entries to files and/or the network in a machine-parsable form. I use the uncaughtException handler on process in order to get uncaught exceptions written out to this logging system. I noticed that if there's no uncaughtException handler, Node will print out an extra stack trace to the console indicating the call site of the <emitter>.emit('error', ...) call which emitted the ultimately-uncaught exception. However, it seems like there's no programmatic way for me to get that extra trace in my own handler.

This feature will solve the problem of being able to programmatically extract this extra — and quite useful! — information in a way that works well with a system that eschews the console.

What is the feature you are proposing to solve the problem?

I don't know what tactic would work best within the larger Node ecosystem, but as a straw-man suggestion:

Add a third argument to the uncaughtException and uncaughtExceptionMonitor callbacks when an "enhanced" error is available, containing information corresponding to the site and target of the emit() call. It could, for example, be a plain object containing an Error representing the call site and an object reference to the emitter itself. But if that's too dangerous, it might instead have strings representing that info. For example (in the former case), the following would nearly duplicate what the current default uncaughtException handler prints out to the console:

process.on('uncaughtException', (err, origin, emitInfo) => {
  console.log('%s', err.stack);
  if (emitInfo) {
    const { emitter, emitSite } = emitInfo;
    console.log(`Emitted 'error' event of ${emitter.constructor.name} instance at:\n%s`,
      emitSite.stack);
  }
});
What alternatives have you considered?

Having a separate process to scrape console output to find things that look like uncaught exceptions, so I can push them into the structured logging system. (Oof.)

Guida per i contributori

Apri la guida per i contributori

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.

Direzione di ricerca

Nell’issue non viene indicato alcun file o test. Inizia tracciando la gestione esistente di Node di process uncaughtException e uncaughtExceptionMonitor insieme al percorso di trace avanzato descritto nel report. Il lavoro è completo quando gli handler possono ricevere programmaticamente le informazioni aggiuntive su emit-site e target quando disponibili, e il comportamento è coperto da test.

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

Valutazione

Stack tecnologico
javascript, nodejs
Ambito
backend
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Attiva
Chiarezza
Da chiarire
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.