vm.Module.evaluate() morphs loader errors into module evaluation rejections

未关闭
#60,242 6 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
需要澄清
活跃度
活跃
技术栈
javascript
领域
backend

调研方向

从 vm.Module.evaluate() 开始,阅读所链接 pull request 的讨论,重点关注当前如何呈现验证错误和 loader 错误。当项目就一种让同步 loader 区分 loader 错误与模块评估错误的方法达成一致时,该 issue 即告完成。

由索引模型根据 Issue 内容生成。

描述

esm stale vm

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.

主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 3 小时
30 天内合并 PR
272

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

nodejs/node 的其他 Issue

查看 nodejs/node 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。