diff --git a/docs/diagnostics.md b/docs/diagnostics.md index 75147162e..db5d009bf 100644 --- a/docs/diagnostics.md +++ b/docs/diagnostics.md @@ -50,7 +50,6 @@ on `Subsystem` and `Code`, not on the wording. | `render` | `first-frame` | Debug | the first frame on Linux, when `VIVA_PROFILE_STARTUP` measures it | | `render` | `window-stats` | Debug | a Linux window closed, with its GPU counters | | `web` | `environment` | Warn | a WebView2 environment could not be created, with `error` | -| `platform` | `reopen-panic` | Error | the macOS reopen handler panicked | The list grows where a failure would otherwise be invisible. A successful operation is reported only when it explains a failure or a measurement (a diff --git a/internal/platform/darwin/reopen_darwin.go b/internal/platform/darwin/reopen_darwin.go index 8cc084069..4b8c843d2 100644 --- a/internal/platform/darwin/reopen_darwin.go +++ b/internal/platform/darwin/reopen_darwin.go @@ -7,7 +7,7 @@ import ( "os" "sync" - "github.com/vivaui/viva/internal/diag" + "github.com/vivaui/viva/internal/platform" ) var applicationReopen struct { @@ -30,12 +30,9 @@ func deliverApplicationReopen() (handled bool) { } defer func() { if value := recover(); value != nil { - // The native handling still runs, but the application's bug is not hidden. - message := fmt.Sprint(value) - if diag.Enabled(diag.Error) { - diag.Report(diag.Error, "platform", "reopen-panic", "the reopen handler panicked", - diag.String("panic", message)) - } + // The native handling still runs, but the application's bug is not hidden: + // it reaches the fault handler like a panic at any other native boundary. + platform.ReportFault("darwin: application reopen", value) fmt.Fprintf(os.Stderr, "viva: reopen handler panicked: %v\n", value) handled = false } diff --git a/internal/platform/darwin/reopen_darwin_test.go b/internal/platform/darwin/reopen_darwin_test.go index 329aef78a..5249fc26e 100644 --- a/internal/platform/darwin/reopen_darwin_test.go +++ b/internal/platform/darwin/reopen_darwin_test.go @@ -2,7 +2,11 @@ package darwin -import "testing" +import ( + "testing" + + "github.com/vivaui/viva/internal/platform" +) func TestApplicationReopenDispatchRunsOutsideLockAndCanBeRemoved(t *testing.T) { application := &nativeApplication{} @@ -29,3 +33,16 @@ func TestApplicationReopenPanicFallsBackToNativeHandling(t *testing.T) { t.Fatal("panicking application reopen handler was reported handled") } } + +func TestApplicationReopenPanicReachesTheFaultHandler(t *testing.T) { + var got platform.Fault + platform.SetFaultHandler(func(fault platform.Fault) { got = fault }) + defer platform.SetFaultHandler(nil) + application := &nativeApplication{} + t.Cleanup(func() { application.SetReopenHandler(nil) }) + application.SetReopenHandler(func() { panic("reopen failure") }) + deliverApplicationReopen() + if got.Where != "darwin: application reopen" || got.Message != "reopen failure" || len(got.Stack) == 0 { + t.Fatalf("fault = %+v", got) + } +}