vm.Module.evaluate() morphs loader errors into module evaluation rejections
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 122k
- Forks
- 37.3k
- Ø Merge
- 4 T. 2 Std.
- Gemergte PRs (30 T.)
- 283
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit vm.Module.evaluate() und lies die Diskussion zum verlinkten Pull Request. Konzentriere dich darauf, wie Validierungs- und Loader-Fehler derzeit gemeldet werden. Das Issue ist abgeschlossen, wenn sich das Projekt auf eine Möglichkeit geeinigt hat, mit der synchrone Loader Loader-Fehler von Fehlern bei der Modulauswertung unterscheiden können.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript
- Bereich
- backend
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Aktiv
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100