Pierre
Pierre

Reputation: 1667

VS-Code won't pause debugger on exception inside Promise

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

Upvotes: 7

Views: 7568

Answers (3)

Pierre
Pierre

Reputation: 1667

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

Upvotes: 1

Tarun Lalwani
Tarun Lalwani

Reputation: 146610

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

Upvotes: 4

Tatarin
Tatarin

Reputation: 1298

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

debugger works without exceptions

Upvotes: 11

Related Questions