Skip to content

Commit 69b7ec8

Browse files
AnnatarHeclaude
andcommitted
feat(cli): display API errors in grep output format
Show errors as formatted output instead of returning them: - JSON format: output {"error": "message"} - Table format: print error in red 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 96816c3 commit 69b7ec8

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

commands/grep.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,16 @@ func commandGrep(c *cli.Context) error {
144144
result, err := model.FetchCommandsFromServer(ctx, endpoint, filter, pagination)
145145
s.Stop()
146146
if err != nil {
147-
return fmt.Errorf("failed to fetch commands: %w", err)
147+
if format == "json" {
148+
errOutput := struct {
149+
Error string `json:"error"`
150+
}{Error: err.Error()}
151+
jsonData, _ := json.MarshalIndent(errOutput, "", " ")
152+
fmt.Println(string(jsonData))
153+
} else {
154+
color.Red.Printf("Error: %s\n", err.Error())
155+
}
156+
return nil
148157
}
149158

150159
slog.Debug("grep result",

0 commit comments

Comments
 (0)