~edwargix/tallyard

47dc769aedf0cf411492db4a98448ae968f90855 — David Florness 2 years ago 20d6fd7
TUI: properly handle panics inside goroutine
1 files changed, 4 insertions(+), 2 deletions(-)

M ui/tui.go
M ui/tui.go => ui/tui.go +4 -2
@@ 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()