-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throw in async function after await is not caught by debugger #4630
Comments
I've found that if I enable first-chance exceptions, I will get called back for a throw after an await but in that case |
Nevermind, I was wrong - the error after the await doesn't generate a first-chance exception either. |
@fatcerberus the /**exception(all):stack();**/
async function f()
{
await null;
throw new Error("*munch*");
}
f().then( function (result) {
console.log('here 1 ' + result);
},
function (error) {
console.log('here 2 ' + error);
}); same is true if you debug in the Edge using F12. |
I am not sure about #4608, but what I meant was it generates the first chance exception. Is that not what you see? |
You say the throw won’t be executed until someone adds a .then() to the promise, which doesn’t make sense since in that case #4608 wouldn’t work (it does). |
hmm, I must be mistaken then. |
Comparing this with HostPromiseRejectionTracker (#4608) is a bit of a misnomer. The detection mechanisms are totally different. With HostPromiseRejectionTracker the trigger is whenever a promise is rejected to check if it's got a handler or not - to be honest I have no idea what the trigger the debugger uses is. The above case: async function f()
{
await null;
throw new Error("*munch*");
}
f(); Roughly de-sugars to: function f()
{
var p = Promise.Resolve(null);
var prom;
p.then(()=>{
try{
throw new Error("*munch*");//
}
catch(e){
prom = Promise.Reject(e);//-> rejected promise with no handler
// -> triggers HostPromiseRejectionTracker
}
}
return prom;
}
f(); (I note that there should be 1 more try catch block and at least one more throwaway promise to write that fully but it just gets unnecessarily messy) The throw definitely fires - but the debugger does not flag for it - you can catch and log the error if wanted of course. |
@rhuanjl Right, I know they’re different mechanisms. I was just referring specifically to akroshg’s assertion that the throw is not executed at all, which clearly isn’t the case or else rejection tracking would be pointless. |
This seems to be the culprit: In the case of the following code: async function f() {
await null;
throw new Error();
}
f(); When deciding whether to pass this exception onto the debugger, ChakraCore considers the thrown exception to both:
While 1) is true, 2) most definitely isn't as there is no |
I've taken a quick look at this, and I believe that the issue is not Async functions at all but rather the way Promise reactions are implemented An alternative repro of this issue would be: Promise.resolve().then(()=>{throw new Error("hunger increases");}); No break point is seen in the debugger for this code. In JavascriptPromise.cpp the following function call occurs in 2 different methods that handle promise reactions: Js::JavascriptExceptionOperators::AutoCatchHandlerExists autoCatchHandlerExists(scriptContext); I believe from looking over the code that this turns off debugger break points until it's disabled again I assume there is a purpose for this - but I'll be honest I don't really understand some parts of this code at the moment, could the fix perhaps be to only set that if the promise IsHandled? |
See PR #5328 for a |
…in promises wouldn't notify debugger Merge pull request #5328 from mike-kaufman:build/mkaufman/support-uncaught-exception-handler-in-promises If an exception was raised inside a promise and the promise didn't have any rejection handlers, we wouldn't notify the debugger that an "unhandled" exception occurred. Fixed this up and added some simple tests for it. This addresses the common cases for promises, but doesn't yet address async/await constructs. Will leave #4630 open for that.
…t" exceptions in promises wouldn't notify debugger Merge pull request #5328 from mike-kaufman:build/mkaufman/support-uncaught-exception-handler-in-promises If an exception was raised inside a promise and the promise didn't have any rejection handlers, we wouldn't notify the debugger that an "unhandled" exception occurred. Fixed this up and added some simple tests for it. This addresses the common cases for promises, but doesn't yet address async/await constructs. Will leave #4630 open for that.
While debugging is enabled, if one throws an error inside of an async function:
Normally, such an error would be intercepted and trigger a breakpoint (
JsDiagDebugEventRuntimeException
):However, if one were to uncomment the
await
in the code above, no breakpoint will be triggered and the promise is just silently rejected:Update (6/26/2018):
There are multiple work items here & I wanted to break them out independently. Will leave this open to track getting this to work w/ async/await. The other issues are:
RE async/await, it looks like we'll need to do some work to update byte-code-generation & possibly jit code so that we understand syntactic constructs that result in a "handled" async functions.
The text was updated successfully, but these errors were encountered: