From d86f739009b28f83d9cb8403b1876c0be7c93b0e Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Mon, 18 Aug 2025 16:50:58 -0300 Subject: [PATCH] fix: fix panic that can happen on sending a message (#817) --- internal/tui/page/chat/chat.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/tui/page/chat/chat.go b/internal/tui/page/chat/chat.go index d6a8b176991d6e16fa0bf293459a5e42c961bd49..a03ca4953f28ed1fbd8ade0902baf68a0a5056f8 100644 --- a/internal/tui/page/chat/chat.go +++ b/internal/tui/page/chat/chat.go @@ -2,6 +2,7 @@ package chat import ( "context" + "fmt" "time" "github.com/charmbracelet/bubbles/v2/help" @@ -649,7 +650,9 @@ func (p *chatPage) changeFocus() { func (p *chatPage) cancel() tea.Cmd { if p.isCanceling { p.isCanceling = false - p.app.CoderAgent.Cancel(p.session.ID) + if p.app.CoderAgent != nil { + p.app.CoderAgent.Cancel(p.session.ID) + } return nil } @@ -687,6 +690,9 @@ func (p *chatPage) sendMessage(text string, attachments []message.Attachment) te session = newSession cmds = append(cmds, util.CmdHandler(chat.SessionSelectedMsg(session))) } + if p.app.CoderAgent == nil { + return util.ReportError(fmt.Errorf("coder agent is not initialized - please check your configuration")) + } _, err := p.app.CoderAgent.Run(context.Background(), session.ID, text, attachments...) if err != nil { return util.ReportError(err) @@ -832,7 +838,7 @@ func (p *chatPage) Help() help.KeyMap { key.WithHelp("esc", "press again to cancel"), ) } - if p.app.CoderAgent.QueuedPrompts(p.session.ID) > 0 { + if p.app.CoderAgent != nil && p.app.CoderAgent.QueuedPrompts(p.session.ID) > 0 { cancelBinding = key.NewBinding( key.WithKeys("esc"), key.WithHelp("esc", "clear queue"),