microsoft / vscode-debugadapter-node

Debug adapter protocol and implementation for VS Code.
Other
273 stars 79 forks source link

Node debugger does not break on re-thrown uncaught exceptions in certain cases #256

Closed dangerbacon closed 2 years ago

dangerbacon commented 2 years ago

In some cases where exceptions are caught and re-thrown in async functions, the vscode debugger does not break on uncaught exceptions. It is easily reproducible with just a few lines of code.

Here is the simplest code I could make to reproduce it:

async function bar()
{
  throw new Error("error!");
}
async function foo()
{
  try { await bar(); } catch(e) { throw e; } //It should break here on the re-throw but doesn't!
}
foo(); //Debugger does NOT break on uncaught exception!

Run this code with the debugger attached and "uncaught exceptions" checked but "caught exceptions" unchecked. The app will crash, but the debugger will not break on uncaught exception.

Just to verify this behavior is inconsistent with the way that synchronous function exceptions are handled, I created the exact same scenario, but with synchronous functions instead of asynchronous functions:

function bar()
{
  throw new Error("error!");
}
function foo()
{
  try { bar(); } catch(e) { throw e; } //It correctly breaks here on the rethrow!
}
foo(); //Debugger does break on uncaught exception, unlike the async version!

When you run this nearly-identical code under the exact same circumstances, the debugger DOES break on the re-thrown uncaught exception as it is supposed to do.

I have attached a test JS file with a more complete set of tests you can run to see that it catches the re-thrown exception in most cases, but does not catch the re-thrown exception when it is an async function calling an async function, catching an error, and re-throwing it.

crashtest.js.txt

Tested on:

connor4312 commented 2 years ago

This reproduces in Chromium, too, so it appears to be a V8 issue. Please file this on: https://bugs.chromium.org/p/chromium/issues/list

dangerbacon commented 2 years ago

Thank you for the follow up! I reproduced in Chrome and filed a V8 bug as you suggested.

Here is the link for anyone in the future who runs across this bug and wants to track it:

Filed V8 Bug