fix(json): standardize JSON output for errors and empty arrays (bd-au0.7)

- Add FatalErrorRespectJSON helper for JSON-aware error output
- Fix bd comments list returning null instead of [] for empty arrays
- Remove redundant local --json flags from show/update/close commands
  that were shadowing the global persistent --json flag
- Update show command error handlers to use FatalErrorRespectJSON

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-12-23 23:53:00 -08:00
parent 12010b25e5
commit 422ec718e7
4 changed files with 556 additions and 539 deletions

View File

@@ -1,6 +1,7 @@
package main
import (
"encoding/json"
"fmt"
"os"
)
@@ -23,6 +24,28 @@ func FatalError(format string, args ...interface{}) {
os.Exit(1)
}
// FatalErrorRespectJSON writes an error message and exits with code 1.
// If --json flag is set, outputs structured JSON to stdout.
// Otherwise, outputs plain text to stderr.
//
// Use this for errors in commands that support --json output.
//
// Example:
//
// if err := store.GetIssue(ctx, id); err != nil {
// FatalErrorRespectJSON("%v", err)
// }
func FatalErrorRespectJSON(format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...)
if jsonOutput {
data, _ := json.MarshalIndent(map[string]string{"error": msg}, "", " ")
fmt.Println(string(data))
} else {
fmt.Fprintf(os.Stderr, "Error: %s\n", msg)
}
os.Exit(1)
}
// FatalErrorWithHint writes an error message with a hint to stderr and exits.
// Use this when you can provide an actionable suggestion to fix the error.
//