-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
process: unhandledRejection support more errors #41682
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
// Verify that ignoring unhandled rejection works fine and that no warning is | ||
// logged. | ||
|
@@ -12,11 +13,25 @@ new Promise(() => { | |
|
||
Promise.reject('test'); | ||
|
||
function lookForMeInStackTrace() { | ||
Promise.reject(new class ErrorLike { | ||
constructor() { | ||
Error.captureStackTrace(this); | ||
this.message = 'ErrorLike'; | ||
} | ||
}()); | ||
} | ||
lookForMeInStackTrace(); | ||
|
||
// Unhandled rejections trigger two warning per rejection. One is the rejection | ||
// reason and the other is a note where this warning is coming from. | ||
process.on('warning', common.mustCall(4)); | ||
process.on('warning', common.mustCall((reason) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What will happen if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ItamarGronich there is a separate test for |
||
if (reason.message.includes('ErrorLike')) { | ||
assert.match(reason.stack, /lookForMeInStackTrace/); | ||
} | ||
}, 6)); | ||
process.on('uncaughtException', common.mustNotCall('uncaughtException')); | ||
process.on('rejectionHandled', common.mustCall(2)); | ||
process.on('rejectionHandled', common.mustCall(3)); | ||
|
||
process.on('unhandledRejection', (reason, promise) => { | ||
// Handle promises but still warn! | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might want to use
Object.hasOwn()
:)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bnb I wanted to but then we can't backport it to older versions of Node - see discussion here: #41682 (comment)