2

I have been getting several errors similar to this one:

(node:30892) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 5): SyntaxError

From these questions (What is Unhandled Promise Rejection and NodeJS UnhandledPromiseRejectionWarning) it seems that these warnings are caused by not having a .catch on a promise after a chain of .then

However, these warnings do not have a file or line number where the problem lies. Is there any way to find this out/narrow it down?

A Jar of Clay
  • 5,622
  • 6
  • 25
  • 39

1 Answers1

3

You can catch the unhandled promise rejection warning, and use the given data to know where it happens.

process.on('unhandledRejection', (reason, p) => {
   console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
});

This gyus here tell us :

enter image description here

Orelsanpls
  • 22,456
  • 6
  • 42
  • 69
  • This prints out: "console.log src\App\app.jsx:9 unhandledRejection" where line 9 is the location of the console.log in process.on, not the location of the actual warning. Logging error instead of error.message gives a trace which is unhelpful. Any ideas? – A Jar of Clay Sep 26 '17 at 11:26
  • 1
    I got this error: console.log src\App\app.jsx:9 Unhandled Rejection at: Promise reason: SyntaxError at XMLHttpRequest.open (\node_modules\jsdom\lib\jsdom\living\xmlhttprequest.js:486:15) at dispatchXhrRequest (\node_modules\axios\lib\adapters\xhr.js:45:13) at xhrAdapter (\node_modules\axios\lib\adapters\xhr.js:12:10) at dispatchRequest (\node_modules\axios\lib\core\dispatchRequest.js:52:10) at process._tickCallback (internal/process/next_tick.js:109:7) Is this the actual source of the error? – A Jar of Clay Sep 26 '17 at 13:17
  • To be fair Idk. I've never used it before, but it seems to be the correct answer looking at the github answer. – Orelsanpls Sep 26 '17 at 13:24
  • This definitely helped, but the upshot is that the line/file that the error originally happened in is not displayed in my case when using this method. – A Jar of Clay Sep 26 '17 at 16:44