question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to know where unhandled promise was triggered (Error: Promise was collected)?

See original GitHub issue

Somewhere 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:closed
  • Created 6 years ago
  • Comments:24 (11 by maintainers)

github_iconTop GitHub Comments

7reactions
paulirishcommented, Apr 25, 2017

Try with node --trace-warnings ? It’ll give you a stack

1reaction
cyrus-andcommented, Aug 5, 2017
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found