Skip to content

Commit f3a568a

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 99875a2 commit f3a568a

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
@@ -205,7 +205,15 @@ func Execute() {
205205
// without jq so the error renders cleanly. Re-resolve the format to
206206
// honor explicit flags like --agent --json.
207207
if errors.IsJQError(err) && cfgJQ != "" {
208-
format, _ := resolveFormat()
208+
format, fmtErr := resolveFormat()
209+
if fmtErr != nil {
210+
// resolveFormat() can fail when --jq conflicts with another flag
211+
// (e.g. --jq --styled). Fall back to a sensible machine format.
212+
format = output.FormatJSON
213+
if cfgAgent || cfgQuiet {
214+
format = output.FormatQuiet
215+
}
216+
}
209217
out = output.New(output.Options{Format: format, Writer: outWriter})
210218
}
211219
if isHumanOutput() {

0 commit comments

Comments
 (0)