How to know where unhandled promise was triggered (Error: Promise was collected)?
See original GitHub issueSomewhere in my code I have a promise where I’m not handling a reject. It’s giving me the error:
Logging in
JQMIGRATE: Migrate is installed with logging active, version 1.4.1
(node:1172) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Promise was collected
(node:1172) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Logging in
Go to NEXT page
I looked through my code a few times but didn’t see an issue. The error in question is somewhere in this block:
function login() {
return new Promise((resolve, reject) => {
try {
var userEl = 'input.username';
var passEl = 'input.password';
document.querySelector(userEl).value = 'username';
document.querySelector(passEl).value = 'password';
$('button.submit').click();
setTimeout(resolve, 2000)
} catch (e) {
return reject(e);
}
});
}
And the block of code that triggers this is in a Runtime.evaluate
block:
...
let state = 'login';
Page.loadEventFired(async() => {
switch (state) {
case 'login':
console.log('Logging in');
let res = await Runtime.evaluate({
expression: `(${login})()`,
awaitPromise: true,
})
state = 'navigateNextPage';
console.log('Go to NEXT page');
await Page.navigate({
url: 'nextPageUrl',
});
break;
case 'navigateNextPage':
...
break;
...
...
some code to navigate to first login page
...
Seems like in the error, the first time the login
invokes in the client, it fails, then the next run is successful. Is there a way to somehow print the stack trace whenever an unhandled Promise rejection occurs?
Issue Analytics
- State:
- Created 6 years ago
- Comments:24 (11 by maintainers)
Top Results From Across the Web
How to find which promises are unhandled in Node.js ...
The correct way to show a full stacktrace for unhandled ES6 Promise ... If you need to find where the error was throwed...
Read more >Tracking Unhandled Promise Rejections - TrackJS
If an error condition arises inside a promise, you “reject” the promise by calling the reject() function with an error. To handle a...
Read more >Creating a JavaScript promise from scratch, Part 7: Unhandled ...
This post covered how browsers track unhandled promise rejections, which is a bit different than how Node.js tracks them. The browser triggers ......
Read more >Process | Node.js v19.3.0 Documentation
The 'unhandledRejection' event is emitted whenever a Promise is rejected and no error handler is attached to the promise within a turn of...
Read more >Browser: Unhandled promise rejection errors not showing on ...
Errors are collected by wrapping Javascript functions - this includes the event listener you are adding, and is done to be able to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Try with
node --trace-warnings
? It’ll give you a stack@mahnunchik I added a FAQ entry.