Skip to content

Commit 143bf4f

Browse files
fix: fatal errors break the terminal due to incorrect bubble tea shutdown (#422)
1 parent 7fcbbe3 commit 143bf4f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

cli/benchmark.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func runBench(ctx *cli.Context, b bench.Benchmark) error {
126126
}
127127
var ui ui
128128
if !globalQuiet && !globalJSON {
129+
registerUI(&ui)
129130
go ui.Run()
130131
}
131132

@@ -289,6 +290,7 @@ func runBench(ctx *cli.Context, b bench.Benchmark) error {
289290
}
290291
monitor.InfoLn("Cleanup Done.")
291292
ui.Wait()
293+
registerUI(nil)
292294
return nil
293295
}
294296

cli/print.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"fmt"
2323
"strings"
2424
"sync"
25+
"sync/atomic"
2526
"unicode"
2627

2728
"github.com/cheggaaa/pb"
@@ -46,6 +47,13 @@ type errorMessage struct {
4647

4748
var printMu sync.Mutex
4849

50+
// Global UI instance for cleanup on fatal errors
51+
var globalUI atomic.Pointer[ui]
52+
53+
func registerUI(u *ui) {
54+
globalUI.Store(u)
55+
}
56+
4957
func printError(data ...any) {
5058
printMu.Lock()
5159
defer printMu.Unlock()
@@ -63,6 +71,10 @@ func fatalIf(err *probe.Error, msg string, data ...any) {
6371
if err == nil {
6472
return
6573
}
74+
// Clean up UI if one is registered
75+
if u := globalUI.Load(); u != nil {
76+
u.Wait()
77+
}
6678
fatal(err, msg, data...)
6779
}
6880

0 commit comments

Comments
 (0)