nodejs / nodejs/node

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

オープン
#60,242 コメント 6 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

esm stale vm
主要言語
JavaScript
スター
122k
フォーク
37.4k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

vm.Module.evaluate() から始め、リンク先の pull request の議論を読んで、検証エラーと loader エラーが現在どのように通知されているかに注目してください。同期 loader が loader エラーとモジュール評価エラーを区別できる方法についてプロジェクトが合意した時点で、issue は完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript
領域
backend
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
活発
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。