From 47dc769aedf0cf411492db4a98448ae968f90855 Mon Sep 17 00:00:00 2001 From: David Florness Date: Fri, 31 Dec 2021 19:54:06 -0600 Subject: [PATCH] TUI: properly handle panics inside goroutine --- ui/tui.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ui/tui.go b/ui/tui.go index 75d0c5a..b6c9584 100644 --- a/ui/tui.go +++ b/ui/tui.go @@ -389,14 +389,15 @@ func ElectionWaitTUI(kill <-chan error, client *mautrix.Client, el *election.Ele frame := tview.NewFrame(votersTextView) frame.SetTitle(el.Title).SetBorder(true) app := newTallyardApplication(kill) - defer func() { + handlePanic := func() { if r := recover(); r != nil { if app.alive { app.Stop() } log.Panicf("ElectionWaitTUI panicked! panic=%s\n%s", r, debug.Stack()) } - }() + } + defer handlePanic() el.RLock() if el.LocalVoter != nil && el.CreateEvt.Sender == el.LocalVoter.JoinEvt.Sender { @@ -431,6 +432,7 @@ func ElectionWaitTUI(kill <-chan error, client *mautrix.Client, el *election.Ele votersTextView.SetText(text) } go func() { + defer handlePanic() var electionStarted bool for app.alive { el.RLock() -- 2.38.4