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 摘要。