Skip to content

Commit 08a2c07

Browse files
committed
Fall back to JSON format when resolveFormat fails in jq error bypass
When --jq conflicts with another format flag (e.g. --styled), resolveFormat() returns an error. Fall back to FormatJSON (or FormatQuiet with --agent/--quiet) instead of defaulting to FormatAuto.
1 parent d31c29b commit 08a2c07

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

internal/commands/root.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,15 @@ func Execute() {
199199
// without jq so the error renders cleanly. Re-resolve the format to
200200
// honor explicit flags like --agent --json.
201201
if errors.IsJQError(err) && cfgJQ != "" {
202-
format, _ := resolveFormat()
202+
format, fmtErr := resolveFormat()
203+
if fmtErr != nil {
204+
// resolveFormat() can fail when --jq conflicts with another flag
205+
// (e.g. --jq --styled). Fall back to a sensible machine format.
206+
format = output.FormatJSON
207+
if cfgAgent || cfgQuiet {
208+
format = output.FormatQuiet
209+
}
210+
}
203211
out = output.New(output.Options{Format: format, Writer: outWriter})
204212
}
205213

0 commit comments

Comments
 (0)