vm.Module.evaluate() morphs loader errors into module evaluation rejections
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 122k
- Fork
- 37.4k
- Merge trung bình
- 4 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 272
Mô tả
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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với vm.Module.evaluate() và đọc phần thảo luận của pull request được liên kết, tập trung vào cách các lỗi xác thực và lỗi loader hiện đang được hiển thị. Issue được hoàn tất khi dự án thống nhất được một cách để các loader đồng bộ phân biệt lỗi loader với lỗi đánh giá module.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript
- Lĩnh vực
- backend
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100