-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show correct stack traces for unhandled promise rejections #188
base: master
Are you sure you want to change the base?
Conversation
This looks very good, the only thing that concerns me is that this will actually terminate the program, whereas the default behaviour is to just print a one line warning, or am I missing something? |
@LinusU you're correct, I didn't realize the aptly named However the same argument could be made for uncaught exceptions - the default behavior is to continue running the program, but node-source-map-support will terminate the program. Is that fine/expected still? Lemme know how you want this to look like and I can try to refactor it |
I believe that the default behaviour for uncaught exceptions is to exit the process, they are not handled equally by Node.js |
My bad, I was testing in the REPL and that behaves differently with uncaught exceptions than running a node script on the command line. I've pushed a new commit which prints + exits on Worth noting that in 8.4 an unhandled promise rejection also prints:
This is documented here: https://nodejs.org/api/deprecations.html#deprecations_dep0018_unhandled_promise_rejections But that's not the behavior yet |
Hmm, just a thought. Do you think it would be possible to just modify the const originalEmit = process.emit
process.emit = function (type, data) {
if (type === 'uncaughtException' || type === 'unhandledRejection') {
if (data && data.stack) data.stack = getErrorSource(error) + '\n' + data.stack
}
oritinalEmit.call(this, type, data)
} |
I gave it a try and ran into the following issue - consider the test file: require('./source-map-support').install();
throw new Error('test'); When I run it I get:
It printed the error source twice. The bottom one is from
and the top one is from the node internal exception handler. This is handled in C code: If I were to remove the I believe it should be possible to modify the arrow string on the error as a hidden field - node does this here: but it requires changing fields that depend on node internals, and may not be consistent between different versions of node. What do you think? |
Great investigation 👍 It's probably best to to not go that route...
actually, I just realised that Node.js standard behaviour is to just print one line, and this will print a stack trace instead. It feels like we shouldn't stray away from the behaviour of standard Node.js, even though I personally think that it's better to print the stack 😄 How about only enabling this when |
Added a deprecation warning that prints once, following https://github.com/nodejs/node/blob/689a64319864433b32235b9d6ac4889f4cdcfea5/lib/internal/process/promises.js#L69-L76. This warning was originally added here: nodejs/node@07dbf73 for all node versions 7.0.0+, so I default Both promise rejections and uncaught exceptions will now only print the source (without stack traces) unless I also updated unhandledRejection emit to now return true - this prevents another duplicate warning that happens when edit: I can try to look at the failing tests on Wednesday |
I think that uncaught exceptions should always print stack trace, it's only unhandled rejection that should only print when the It seems like that is why the tests are failing as well... |
it's sad that this PR got stuck, i wasted a lot of time trying to get this module to work because i thought i was doing something wrong on my side, as unhandled promise rejections didn't show the correct stack trace |
@sungshon A year later, me too. Any way to bump this up somehow? |
Still can't ouput correct stack. |
Hi,
When an ES6 promise is rejected without being handled, node logs it to the console:
and emits an
unhandledRejection
event with the uncaught error. This PR adds support in the same way thatuncaughtException
is handled, and prints the correct stacktrace:Thanks,