nodejs / nodejs/node

Synchronous exceptions in ES modules are always 'caught'

Open
#50,430 9 comments 11 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

confirmed-bug esm inspector v8 engine
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

Version

20.3.1

Platform

Darwin mbp.peet.io 22.6.0 Darwin Kernel Version 22.6.0: Fri Sep 15 13:39:52 PDT 2023; root:xnu-8796.141.3.700.8~1/RELEASE_X86_64 x86_64

Subsystem

inspector

What steps will reproduce the bug?
  1. Start a program containing throw new Error('foo'); in an ES module
  2. Attach a debugger, like devtools or VS Code's debugger, and enable "pause on uncaught exceptions"
  3. Run the program
How often does it reproduce? Is there a required condition?

100%

What is the expected behavior? Why is that the expected behavior?

The runtime should pause on the throw line

What do you see instead?

The runtime does not pause and the program exits

Additional information

First reported in https://github.com/microsoft/vscode-js-debug/issues/1861

Guessing this is because module evaluation is in a try/catch. Wonder if there's any machinery that can be used to mark containing exceptions as uncaught

https://github.com/nodejs/node/blob/0a0b8dfd0d3684d6602599e1f0d9d935b3758700/lib/internal/modules/esm/module_job.js#L217-L219

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lib/internal/modules/esm/module_job.js around lines 217-219 and reproduce the issue using an ES module containing a synchronous throw with an attached debugger. Trace how the inspector handles the exception during module evaluation; done means the debugger pauses on the throw when pause on uncaught exceptions is enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.