Please consider the following code:
new Promise((resolve, reject) => {
breaksomething() //won't pause
})
breaksomething() //pause as expected!
I am expecting my debugger to halt execution - because of an undefined function - at the line breaksomething()
inside the promise
... However I am only getting the following error output:
"ReferenceError: breaksomething is not defined"
(without pausing). Everywhere else the debugger is pausing as expected when an exception is encountered, the problem is only inside a Promise scope. I do have both All Exceptions and Uncaught Exceptions ticked under breakpoints.
I am using:
Visual Studio Code 1.17.2
Node 8.8.1
Inspector debugger
UPDATE Per latest update on a known issue from Microsoft team it was a known issue in VS code.
You have to UNCHECK All Exceptions
and Uncaught Exceptions
in breakpoints settings in VS code in order for that to work
After debugging I found that this is happening because Promise library is implement in Native code
So when you create a Promise, the function inside is actually called by the Native code and the exception goes back to it. This might be one of the reasons that it is not caught by VS debugger.
Is it impossible to do so? Well WebStorm from JetBrains is able to break on such exceptions also. Now how they do it and why VS Code is not able to do it, is beyond my understanding. It would be best to open a issue against VS code and refer that WebStorm does it. So it is technically possible to break on such exceptions
I am still unclear why this issue is happening but I found a workaround. Just install bluebird and add the following in the initialisation code of your app:
global.Promise = require("bluebird");
...this will override the default nodejs Promise and break as expected when "All exceptions" is ticked
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With