on main help sign in
fix: add panic recovery to TUI subscription handler

- Add panic recovery with graceful TUI shutdown to app.Subscribe method - Ensures application doesn't crash if TUI subscription loop panics - Logs panic details to timestamped files for debugging - Maintains consistency with other critical goroutines in codebase

commit8dff4d64ff01860b3d8812d60907b1702ec34631 authorKujtim Hoxha <kujtimii.h@gmail.com> dateTue 8 Jul 2025, 17:38 (1 year ago) parenteeeef60
1 file changed+6
internal/app/app.go+6
internal/app/app.go+6
@@ -16,6 +16,7 @@ import (
1616 "github.com/charmbracelet/crush/internal/format"
1717 "github.com/charmbracelet/crush/internal/history"
1818 "github.com/charmbracelet/crush/internal/llm/agent"
19+ "github.com/charmbracelet/crush/internal/log"
1920 "github.com/charmbracelet/crush/internal/pubsub"
2021
2122 "github.com/charmbracelet/crush/internal/lsp"
@@ -230,6 +231,11 @@ func (app *App) InitCoderAgent() error {
230231}
231232
232233func (app *App) Subscribe(program *tea.Program) {
234+ defer log.RecoverPanic("app.Subscribe", func() {
235+ slog.Info("TUI subscription panic - attempting graceful shutdown")
236+ program.Quit()
237+ })
238+
233239 app.tuiWG.Add(1)
234240 tuiCtx, tuiCancel := context.WithCancel(app.globalCtx)
235241 app.cleanupFuncs = append(app.cleanupFuncs, func() {