Skip to content

Commit 52b5c9b

Browse files
committed
fix: handle JSON mode properly for error cases
- profiles get: output null instead of pterm error when profile not found - invoke: output JSON error object instead of human-readable text when API call fails in JSON mode Addresses cursor[bot] review feedback.
1 parent 7070bc5 commit 52b5c9b

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

cmd/invoke.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ func runInvoke(cmd *cobra.Command, args []string) error {
9696
// Create the invocation
9797
resp, err := client.Invocations.New(cmd.Context(), params, option.WithMaxRetries(0))
9898
if err != nil {
99+
if jsonOutput {
100+
// In JSON mode, output error as JSON object
101+
errObj := map[string]interface{}{"error": err.Error()}
102+
if apiErr, ok := err.(*kernel.Error); ok {
103+
errObj["status_code"] = apiErr.StatusCode
104+
}
105+
bs, _ := json.Marshal(errObj)
106+
fmt.Println(string(bs))
107+
return fmt.Errorf("invocation failed: %w", err)
108+
}
99109
return handleSdkError(err)
100110
}
101111
// Log the invocation ID for user reference

cmd/profiles.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ func (p ProfilesCmd) Get(ctx context.Context, in ProfilesGetInput) error {
115115
return util.CleanedUpSdkError{Err: err}
116116
}
117117
if item == nil || item.ID == "" {
118+
if in.Output == "json" {
119+
fmt.Println("null")
120+
return nil
121+
}
118122
pterm.Error.Printf("Profile '%s' not found\n", in.Identifier)
119123
return nil
120124
}

0 commit comments

Comments
 (0)