Promise rejection in timeout (versus module-level) treated as unhandled by debugger
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 122k
- Fork
- 37.3k
- Merge trung bình
- 4 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 283
Mô tả
Version
v22.4.0
Platform
Darwin Hypothesis.local 24.0.0 Darwin Kernel Version 24.0.0: Thu Jun 20 20:36:19 PDT 2024; root:xnu-11215.0.115.501.3~1/RELEASE_ARM64_T8103 arm64
Subsystem
No response
What steps will reproduce the bug?
Create this script:
setTimeout(() => {
Promise.reject().catch(() => { })
}, 1)
And run it in the debugger with break on Uncaught enabled.
How often does it reproduce? Is there a required condition?
Every time. Note this does not happen if Promise.reject() is at top level instead of wrapped in setTimeout().
What is the expected behavior? Why is that the expected behavior?
It is expected that the debugger does (1) not pause on such a promise or (2) only pauses on such a promise if breakOnException is enabled.
The HTML spec guarantees that promise rejections are not considered unhandled if a handler is then synchronously attached.
What do you see instead?
Node breaks synchronously on the creation of the rejected promise. Similar issues happen when using the VSCode debugger and Chrome debugger.
node inspect promisetest.js
< Debugger listening on ws://127.0.0.1:9229/d18cff1f-6886-4ff6-9a4f-404128bd150a
< For help, see: https://nodejs.org/en/docs/inspector
<
< Debugger attached.
<
ok
Break on start in promisetest.js:1
> 1 setTimeout(() => {
2 Promise.reject().catch(() => { })
3 }, 1)
debug> breakOnUncaught
debug> c
promiseRejection in promisetest.js:2
1 setTimeout(() => {
> 2 Promise.reject().catch(() => { })
3 }, 1)
4
Additional information
A downstream issue where this interferes with usage of the web streams API: #51093
I too have been incredibly confused by this, as it makes it seem like even correct usage of promises is developer error.
VSCode reports this as "Exception has occurred" instead of "promiseRejection".
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 bằng cách chạy script được cung cấp với node inspect, breakOnUncaught và debugger được gắn vào, sau đó so sánh promise rejection được bọc trong timeout với trường hợp ở cấp cao nhất. Theo dõi cách các promise rejection được tạo bên trong setTimeout được báo cáo khi một handler được gắn đồng bộ; hoàn tất khi debugger không tạm dừng đối với rejection đã được xử lý đó, trừ khi breakOnException được bật.
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, node.js
- Lĩnh vực
- devtools
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 48/100