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.

Error details for UnhandledPromiseRejectionWarning

See original GitHub issue

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 1.17.0
  • Platform / OS version: WSL (Bash on Windows)
  • Node.js version: v12.4.0

What steps will reproduce the problem?

const clickAndWait = function(container, target, btn) {
    return container.evaluate((target, btnNext) => {
        return new Promise((resolve, reject) => {
            let observer = new MutationObserver(function() {
                observer.disconnect(); // use the mutation observer only once
                resolve();
            });
            observer.observe(target, { childList: true, subtree: true, });

            // some reasonable timeout, in case loading got stuck
            setTimeout(reject.bind(this, 'timeout'), 5000);

            // puppeteer click() doesn't work, must use native click() in eval
            btn.click();
        });
    }, target, btn);
};

await ph.clickAndWait(iframe, someContainer, btnNext);

What is the expected result? The function evaluates, MutationObserver is set up, the button is clicked, MutationObserver resolves the Promise and await proceeds.

What happens instead? Error:

(node:4335) UnhandledPromiseRejectionWarning: Error: Evaluation failed: [object Object]
    at ExecutionContext._evaluateInternal (/d/DATA/WDH/Webseite/workspaces/Ari/www/application/noch-frei/crawl/puppeteer-launch/node_modules/puppeteer/lib/ExecutionContext.js:122:13)

(node:4335) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:4335) [DEP0018] 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.

How to catch the Promise exception and log the Object so I can read the error messages or at least find out what failed during the evaluation?

Also, this helper method worked in the past, after changing some of the code and moving its invocations, this error occurs.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
aslushnikovcommented, Jul 16, 2019

Indeed, we do horrible job showing some errors 🤦‍♂️

For example, the following doesn’t tell me why exactly evaluation has failed:

const puppeteer = require('puppeteer');

puppeteer.launch().then(async browser => {
  const page = await browser.newPage();
  await page.evaluate(() => new Promise(() => {
    does_not_exist.click();
  })).catch(e => {
    console.log(e);
  });
  await browser.close();
})

Gives me an error:

aslushnikov:~/prog/puppeteer(master)$ node a.js
Error: Evaluation failed: [object Object]
    at ExecutionContext._evaluateInternal (/Users/aslushnikov/prog/puppeteer/lib/ExecutionContext.js:122:13)
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
    at async ExecutionContext.evaluate (/Users/aslushnikov/prog/puppeteer/lib/ExecutionContext.js:48:12)
    at async /Users/aslushnikov/prog/puppeteer/a.js:5:3
  -- ASYNC --
    at ExecutionContext.<anonymous> (/Users/aslushnikov/prog/puppeteer/lib/helper.js:111:15)
    at DOMWorld.evaluate (/Users/aslushnikov/prog/puppeteer/lib/DOMWorld.js:112:20)
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
  -- ASYNC --
    at Frame.<anonymous> (/Users/aslushnikov/prog/puppeteer/lib/helper.js:111:15)
    at Page.evaluate (/Users/aslushnikov/prog/puppeteer/lib/Page.js:782:43)
    at Page.<anonymous> (/Users/aslushnikov/prog/puppeteer/lib/helper.js:112:23)
    at /Users/aslushnikov/prog/puppeteer/a.js:5:14
    at processTicksAndRejections (internal/process/task_queues.js:85:5)

Not a single word about ReferenceError!

Whereas CDP does tell us the reason:

aslushnikov:~/prog/puppeteer(master)$ DEBUG=* node a.js
....
  puppeteer:protocol SEND ► {"sessionId":"EE1E9F39496DD1867256AC7E74527119","method":"Runtime.callFunctionOn","params":{"functionDeclaration":"() => {\n      btn.click();\n  }\n//# sourceURL=__puppeteer_evaluation_script__\n","executionContextId":1,"arguments":[],"returnByValue":true,"awaitPromise":true,"userGesture":true},"id":16} +1ms
  puppeteer:protocol ◀ RECV {"id":16,"result":{"result":{"type":"object","subtype":"error","className":"ReferenceError","description":"ReferenceError: btn is not defined\n    at __puppeteer_evaluation_script__:2:7","objectId":"{\"injectedScriptId\":1,\"id\":1}"},"exceptionDetails":{"exceptionId":1,"text":"Uncaught","lineNumber":1,"columnNumber":6,"scriptId":"11","stackTrace":{"callFrames":[{"functionName":"","scriptId":"11","url":"__puppeteer_evaluation_script__","lineNumber":1,"columnNumber":6}]},"exception":{"type":"object","subtype":"error","className":"ReferenceError","description":"ReferenceError: btn is not defined\n    at __puppeteer_evaluation_script__:2:7","objectId":"{\"injectedScriptId\":1,\"id\":2}"}}},"sessionId":"EE1E9F39496DD1867256AC7E74527119"} +1ms
.....
1reaction
brilloutcommented, Oct 6, 2020

Indeed, we do horrible job showing some errors For example, the following doesn’t tell me why exactly evaluation has failed

Anything new on that end?

I still can’t get puppeteer to show me browser-side errors, which is particularly inconvenient when considering puppeteer an automation tool for unit testing 😞.

Other than that, thanks for this lovely tool.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting a UnhandledPromiseRejectionWarning when testing ...
The "Unhandled promise rejection" is also caused by the failed assertion, because if an error is thrown in a catch() handler, and there...
Read more >
Unhandled Promise Rejections in Node.js - The Code Barbarian
Promise.reject(new Error('woops')); /* Output: $ node test.js (node:7741) UnhandledPromiseRejectionWarning: Unhandled promise rejection ...
Read more >
Tracking Unhandled Promise Rejections - TrackJS
When a promise is rejected, it looks for a rejection handler. If it finds one, like in the example above, it calls the...
Read more >
unhandledpromiserejectionwarni...
unhandledpromiserejectionwarning : error: request failed with status code 404 ... That or expand the error handling to display the response information.
Read more >
UnhandledPromiseRejectionWar...
In Post, We discuss How To resolve UnhandledPromiseRejectionWarning: Unhandled promise rejection Error in javascript,node.js, React.js, Gatsby.js, ...
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