-
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
Debugger doesn't catch error thrown inside for...of loop immediately #3685
Comments
There's also this oddity:
It paused execution on a statement that shouldn't even be reached. 😕 |
Same behavior as Edge browser for arrow functions so this is not specific to JsRT debugger but a runtime issue. |
The arrow function is a bit of a red herring. I put it in to illustrate but the actual problem is that an exception thrown from inside a for...of loop often causes a partial unwind before the debugger intercepts it. I've seen this even with regular functions, so it's not specific to arrows. |
yes this is issue with for..of nothing related to arrow function. Also doesn't repro with for..in |
we convert for (var i of item) {
...
} to similar (not exactly same) for (var i of item) {
try {
...
} catch (e) {
throw e;
}
} for iterator close support. In the debug mode we actually re-throw in the catch. (this code is hidden). But in the debugger as the code is hidden we take the last statement in the for..of. |
@akroshg Yeah, but in my case the breakpoint doesn’t trigger until after the entire stack frame of the function containing the for...of has been unwound. |
Test case (with /**exception(uncaught):stack();**/
for (let x of [1, 2, 3, 4]) {
(() => { throw new Error('Exception thrown from within for-of')})();
print('what the what');
} It appears that since we desugar for-of using try-catch, the exception handling code thinks that the exception thrown inside of the for-of loop body above is "handled" (see |
@zenparsing Just for the record, I had made a pull request to remove the |
@fatcerberus AutoCatchHandlerExists is the method used for preventing a debugger break inside a try/catch block and inside an async function - the commonality of method doesn't mean the fix is the same here. This one is to do with the internal sugaring of for-of (see the explanation I wrote out at #6314) and could be fixed fairly simply - though the fix I can think of won't fix #6314 a better/more complex fix will be needed to do both. The Async function issue is rather different - there isn't currently a way of determining if the async function's promise is going to be handled or not so if the debugger breaks on an exception in an async function it may be one that had a handler or it may not - removing the AutoCatchHandlerExists from async functions therefore meant the debugger breaking when it shouldn't (as well as when it should). |
I have JsDiagBreakOnExceptionAttributeUncaught enabled. Normally, errors are caught as soon as they're thrown. I've noticed, however, that if an error is thrown inside a for...of loop, entire stack frames can be unwound before the error is intercepted, losing valuable debugging information in the process. Here's an example, illustrated by my SSj debugger:
Notice the stacktrace of the Error object includes the arrow function, but the
backtrace
output does not, and the breakpoint actually triggered later, completely outside the for...of loop.If I move the throw outside the loop, then it works as expected:
The text was updated successfully, but these errors were encountered: