From bcd23c587b025488eea0aa6ba35a9bd59eab7779 Mon Sep 17 00:00:00 2001 From: Leo225 Date: Fri, 31 Jul 2026 19:30:28 +0800 Subject: [PATCH] fix: handle input and database read errors in client and doctor commands (#1480) Added error handling for input reading in the agent chat client and for database row reading in the doctor commands, ensuring that errors are reported clearly to the user. --- cmd/agent_chat_client.go | 4 ++++ cmd/doctor.go | 8 ++++++++ cmd/gateway_subagent_announce_format.go | 9 ++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/cmd/agent_chat_client.go b/cmd/agent_chat_client.go index 6a6d4c59..d2a89ada 100644 --- a/cmd/agent_chat_client.go +++ b/cmd/agent_chat_client.go @@ -76,6 +76,10 @@ func runClientMode(cfg *config.Config, addr, agentName, message, sessionKey stri } fmt.Printf("\n%s\n\n", resp) } + if err := scanner.Err(); err != nil { + fmt.Fprintf(os.Stderr, "Input error: %v\n", err) + os.Exit(1) + } } // wsConnect sends the connect RPC and waits for auth response. diff --git a/cmd/doctor.go b/cmd/doctor.go index 8edeaa1d..6034457f 100644 --- a/cmd/doctor.go +++ b/cmd/doctor.go @@ -187,6 +187,10 @@ func checkDBChannels(db *sql.DB) { label := fmt.Sprintf("%s/%s", channelType, name) fmt.Printf(" %-24s %s\n", label+":", status) } + if err := rows.Err(); err != nil { + fmt.Printf(" (could not read channels: %s)\n", err) + return + } if !found { fmt.Println(" (none configured in database)") } @@ -218,6 +222,10 @@ func checkDBProviders(db *sql.DB) { } fmt.Printf(" %-16s %s\n", displayName+":", status) } + if err := rows.Err(); err != nil { + fmt.Printf(" (could not read providers: %s)\n", err) + return + } if !found { fmt.Println(" (none configured in database)") } diff --git a/cmd/gateway_subagent_announce_format.go b/cmd/gateway_subagent_announce_format.go index 32cd6051..0fce1a5a 100644 --- a/cmd/gateway_subagent_announce_format.go +++ b/cmd/gateway_subagent_announce_format.go @@ -14,11 +14,14 @@ func buildMergedSubagentAnnounce(entries []subagentAnnounceEntry, roster tools.S if len(entries) == 1 { e := entries[0] - statusLabel := "completed successfully" - if e.Status == "failed" { + var statusLabel string + switch e.Status { + case "failed": statusLabel = "failed" - } else if e.Status == "cancelled" { + case "cancelled": statusLabel = "was cancelled" + default: + statusLabel = "completed successfully" } fmt.Fprintf(&sb, "[System Message] A subagent task %q just %s.\n\nResult:\n%s\n\nStats: runtime %s, iterations %d, tokens %d in / %d out\n", e.Label, statusLabel, e.Content,