Promise rejection in timeout (versus module-level) treated as unhandled by debugger
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.4k
- 平均合并
- 4 天 3 小时
- 30 天内合并 PR
- 272
描述
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".
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先运行提供的脚本,使用 node inspect、breakOnUncaught 并附加调试器,然后将 timeout 包装的 rejection 与顶层情况进行比较。跟踪在同步附加处理程序时,setTimeout 内创建的 promise rejection 是如何报告的;当调试器不会因该已处理的 rejection 而暂停时完成,除非启用了 breakOnException。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, node.js
- 领域
- devtools
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100