Skip to content

Commit 224096d

Browse files
committed
Address PR review feedback
- Check write error from fmt.Fprintln for non-string jq results - Move flag conflict checks before Parse/Compile so the user sees the actionable conflict message first
1 parent e80fc16 commit 224096d

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

internal/commands/jq.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ func (w *jqWriter) Write(p []byte) (int, error) {
6868
if err != nil {
6969
return 0, errors.ErrJQRuntime(fmt.Errorf("result not serializable: %w", err))
7070
}
71-
fmt.Fprintln(w.dest, string(raw))
71+
if _, err := fmt.Fprintln(w.dest, string(raw)); err != nil {
72+
return 0, err
73+
}
7274
}
7375
}
7476
return len(p), nil

internal/commands/root.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,23 @@ var rootCmd = &cobra.Command{
7575
Use fizzy to manage boards, cards, comments, and more from your terminal.`,
7676
Version: "dev",
7777
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
78-
// Early jq validation: parse + compile before RunE so invalid
79-
// expressions are rejected with no side effects.
78+
// Early jq validation: check flag conflicts first (actionable message),
79+
// then parse + compile before RunE so invalid expressions are rejected
80+
// with no side effects.
8081
if cfgJQ != "" {
82+
if cfgIDsOnly {
83+
return errors.ErrJQConflict("--ids-only")
84+
}
85+
if cfgCount {
86+
return errors.ErrJQConflict("--count")
87+
}
8188
q, err := gojq.Parse(cfgJQ)
8289
if err != nil {
8390
return errors.ErrJQValidation(err)
8491
}
8592
if _, err := gojq.Compile(q, gojq.WithEnvironLoader(os.Environ)); err != nil {
8693
return errors.ErrJQValidation(err)
8794
}
88-
if cfgIDsOnly {
89-
return errors.ErrJQConflict("--ids-only")
90-
}
91-
if cfgCount {
92-
return errors.ErrJQConflict("--count")
93-
}
9495
}
9596

9697
// Resolve output format from parsed flags (must happen post-parse).

0 commit comments

Comments
 (0)