Expose the "enhanced" stack trace from uncaught exceptions to the uncaughtException
and uncaughtExceptionMonitor
handlers on process
#55838
Labels
events
Issues and PRs related to the events subsystem / EventEmitter.
feature request
Issues that request new features to be added to Node.js.
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 onprocess
in order to get uncaught exceptions written out to this logging system. I noticed that if there's nouncaughtException
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
anduncaughtExceptionMonitor
callbacks when an "enhanced" error is available, containing information corresponding to the site and target of theemit()
call. It could, for example, be a plain object containing anError
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 defaultuncaughtException
handler prints out to the console: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.)
The text was updated successfully, but these errors were encountered: