nodejs / nodejs/node

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

Aperta
#60,242 6 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

esm stale vm
Lingua principale
JavaScript
Stelle
122k
Fork
37.3k
Merge medio
4g 2h
PR unite (30g)
283

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da vm.Module.evaluate() e leggi la discussione della pull request collegata, concentrandoti su come vengono attualmente segnalati gli errori di validazione e del loader. L'issue è completata quando il progetto concorda su un modo che consenta ai loader sincroni di distinguere gli errori del loader dagli errori di valutazione del modulo.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript
Ambito
backend
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Attiva
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.