From ed55715b6bd886e33a821b0aeb3c91d57523bdf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E6=99=BA=E8=B6=850668000959?= Date: Mon, 15 Jun 2026 20:31:34 +0800 Subject: [PATCH] fix(seahorse): handle json.Marshal errors in grep and expand tools --- pkg/seahorse/tool_expand.go | 5 ++++- pkg/seahorse/tool_grep.go | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/seahorse/tool_expand.go b/pkg/seahorse/tool_expand.go index 749c9cd6c..7731cb696 100644 --- a/pkg/seahorse/tool_expand.go +++ b/pkg/seahorse/tool_expand.go @@ -124,6 +124,9 @@ func (t *ExpandTool) Execute(ctx context.Context, args map[string]any) *tools.To "tokenCount": result.TokenCount, "messages": messages, } - data, _ := json.Marshal(output) + data, err := json.Marshal(output) + if err != nil { + return tools.ErrorResult(fmt.Sprintf("failed to marshal expand result: %v", err)) + } return tools.NewToolResult(string(data)) } diff --git a/pkg/seahorse/tool_grep.go b/pkg/seahorse/tool_grep.go index 9671d2a7f..5ea32624b 100644 --- a/pkg/seahorse/tool_grep.go +++ b/pkg/seahorse/tool_grep.go @@ -167,6 +167,9 @@ func (t *GrepTool) Execute(ctx context.Context, args map[string]any) *tools.Tool output["hint"] = result.Hint } - data, _ := json.Marshal(output) + data, err := json.Marshal(output) + if err != nil { + return tools.ErrorResult(fmt.Sprintf("failed to marshal grep result: %v", err)) + } return tools.NewToolResult(string(data)) }