microsoft / vscode-js-debug

A DAP-compatible JavaScript debugger. Used in VS Code, VS, + more
MIT License
1.67k stars 279 forks source link

Debugger not stopping on uncaught exceptions within a top-level await #2057

Closed rendmath closed 1 month ago

rendmath commented 1 month ago

Describe the bug The debugger does not stop on uncaught exceptions from a Node.js library if the call is nested within a top-level await.

To Reproduce

package.json

{
  "type": "module"
}

index.js

import { writeFile } from "fs/promises";

await fail();

export async function fail() {
  await writeFile("does/not/exist", "hello");
}

launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "skipFiles": ["<node_internals>/**"],
      "program": "${workspaceFolder}/index.js"
    }
  ]
}
  1. Setup the project as detailed above.
  2. Check "Caught Exceptions" and "Uncaught Exceptions" in the debugger panel.
  3. Hit F5.
  4. No breakpoint is hit.

Log File Debug console.

C:\Program Files\nodejs\node.exe .\index.js
Uncaught Error Error: ENOENT: no such file or directory, open 'C:\sources\personal\top-level-await-debug\does\not\exist'
    --- await ---
    at runEntryPointWithESMLoader (internal/modules/run_main:139:19)
    at executeUserEntryPoint (internal/modules/run_main:173:5)
    at <anonymous> (internal/main/run_main_module:30:49)
run_main:139
Process exited with code 1

vscode-debugadapter-6410230d.json.gz

VS Code Version: 1.92.1

connor4312 commented 1 month ago

This is a bug in Node.js: https://github.com/nodejs/node/issues/50430