Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions internal/platform/darwin/reopen_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
"sync"

"github.com/vivaui/viva/internal/diag"
"github.com/vivaui/viva/internal/platform"
)

var applicationReopen struct {
Expand All @@ -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
}
Expand Down
19 changes: 18 additions & 1 deletion internal/platform/darwin/reopen_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

package darwin

import "testing"
import (
"testing"

"github.com/vivaui/viva/internal/platform"
)

func TestApplicationReopenDispatchRunsOutsideLockAndCanBeRemoved(t *testing.T) {
application := &nativeApplication{}
Expand All @@ -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)
}
}
Loading