vm.Module.evaluate() morphs loader errors into module evaluation rejections
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 122k
- Forks
- 37.3k
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 283
Description
This came up in https://github.com/nodejs/node/pull/60205#discussion_r2423587581 when I was trying to make vm.Module.evaluate() return the module evaluation promise as-is (so synchronously fulfilled for synthetic modules and source text modules without TLA). Currently the validation errors, ERR_VM_MODULE_STATUS, THROW_ERR_SCRIPT_EXECUTION_TIMEOUT, and THROW_ERR_SCRIPT_EXECUTION_INTERRUPTED would always be rejected, so for a synchronous loader, they would either have to expose these underlying rejections to users when the loading goes wrong, or be forced to become asynchronous as it cannot catch these errors synchronously and paint it over. i.e. they cannot do something like this:
function syncLoad() {
try {
mod.evaluate();
} catch(e) { // This allows the user to get the loader errors synchronously
if (e.code === 'ERR_VM_MODULE_STATUS' ||
e.code === 'ERR_SCRIPT_EXECUTION_INTERRUPTED' ||
e.code === 'ERR_SCRIPT_EXECUTION_TIMEOUT') {
// fix it up and try again, or error and explain to user what to do
// but hide the errors that do not directly come from module code
// as implementation detail
}
}
if (mod.status === 'errored') {
throw mod.error; // It's an evaluation error from the module code
}
return mod.namespace;
}
Opening a separate issue to discuss if there's another way to make this possible other than just making it throw these loader errors synchronously.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with vm.Module.evaluate() and read the linked pull request discussion, focusing on how validation and loader errors are currently surfaced. The issue is done when the project agrees on a way for synchronous loaders to distinguish loader errors from module evaluation errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100