Skip to content

fix(darwin): reopen 处理函数的 panic 交给 fault handler - #20

Merged
xiaoyumuxi merged 2 commits into
mainfrom
lithe/reopen-fault-report
Nov 15, 2026
Merged

xiaoyumuxi merged 2 commits into
mainfrom
lithe/reopen-fault-report

Conversation

@xiaoyumuxi

Copy link
Copy Markdown

关联:1lck/Lithe-IDEA#1949(panic 全部进日志),配套 1lck/Lithe-IDEA#1955;上游 PR vivaui#288(同一提交,基于上游 main)。

问题

macOS 的 deliverApplicationReopen 恢复应用 reopen 处理函数的 panic 后,只写了诊断流的 platform/reopen-panic 和 stderr,没有调用 platform.ReportFault。因此 app.SetFaultHandler 装的处理函数收不到这次 panic。Lithe 的统一日志就是靠这个处理函数记录 app.runtime.panic_interrupted 的,所以这一处 panic 不会进 Lithe 日志。其他原生边界(AppKit 视图回调、剪贴板回调、Windows 窗口过程、COM 方法、钩子)都已经走 ReportFault。

改动

  • internal/platform/darwin/reopen_darwin.go:recover 后调用 platform.ReportFault("darwin: application reopen", value)。应用的 fault handler 能收到消息和发生 panic 时的栈;诊断流在监听时会收到 app/fault(带 where 和 stack)。原生回退(handled = false)和 stderr 输出不变。
  • 删除 platform/reopen-panic 事件(代码和 docs/diagnostics.md 中的一行),避免同一次 panic 报两遍。
  • 新增测试 TestApplicationReopenPanicReachesTheFaultHandler,检查 Where、Message 和非空栈。

其余 recover 点的排查

internal/platform 下其余 recover() 都已调用 platform.ReportFault,或者不是应用故障:runStateFor 丢弃窗口释放后迟到的回调;catchJS 把 JS 异常作为 error 返回;fault 路径自身的保护。internal/diag 中的 recover 是诊断流自身的保护;cmd/viva/vet.go 是命令行工具。

验证

  • go test ./internal/platform/darwin ./internal/platform ./internal/diag ./app ./diagnostics:macOS arm64 在 fork main(4829f2b)和上游 main(f465bad)两个基线上都通过。

Lithe 的 go.mod 固定版本由团队按流程升级,本 PR 不涉及。

deliverApplicationReopen recovered a panic from the application's reopen
handler but only wrote it to the diagnostic stream as platform/reopen-panic
and to stderr, so a handler installed with app.SetFaultHandler never saw
it, unlike a panic at every other native boundary. It now goes through
platform.ReportFault as "darwin: application reopen", which delivers it to
the application's handler and, while the stream is listening, as app/fault
with the stack. The platform/reopen-panic event is removed so one panic is
not reported twice.
@xiaoyumuxi
xiaoyumuxi merged commit 27ad1d7 into main Nov 15, 2026
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant