Fix widespread double JSON encoding bug in daemon RPC calls (bd-1048, bd-4ec8)

Multiple CLI commands had a systematic bug where ResolveID responses were
incorrectly converted using string(resp.Data) instead of json.Unmarshal.
Since resp.Data is json.RawMessage (already JSON-encoded), this preserved
the JSON quotes, causing IDs to become "bd-1048" instead of bd-1048.
When re-marshaled for subsequent RPC calls, these became double-quoted
("\"bd-1048\""), causing database lookups to fail.

Bugs fixed:
1. Nil pointer dereference in handleShow - added nil check after GetIssue
2. Double JSON encoding in 12 locations across 4 commands:
   - bd show (3 instances in show.go)
   - bd dep add/remove/tree (5 instances in dep.go)
   - bd label add/remove/list (3 instances in label.go)
   - bd reopen (1 instance in reopen.go)

All instances replaced string(resp.Data) with proper json.Unmarshal.
Removed debug logging added during investigation.

Tested: All affected commands now work correctly with daemon mode.
This commit is contained in:
Steve Yegge
2025-11-02 22:34:24 -08:00
parent 63ff9b93bc
commit 481649a605
9 changed files with 67 additions and 37 deletions

View File

@@ -83,7 +83,10 @@ var labelAddCmd = &cobra.Command{
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
continue
}
fullID = string(resp.Data)
if err := json.Unmarshal(resp.Data, &fullID); err != nil {
fmt.Fprintf(os.Stderr, "Error unmarshaling resolved ID: %v\n", err)
continue
}
} else {
fullID, err = utils.ResolvePartialID(ctx, store, id)
if err != nil {
@@ -125,7 +128,10 @@ var labelRemoveCmd = &cobra.Command{
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
continue
}
fullID = string(resp.Data)
if err := json.Unmarshal(resp.Data, &fullID); err != nil {
fmt.Fprintf(os.Stderr, "Error unmarshaling resolved ID: %v\n", err)
continue
}
} else {
fullID, err = utils.ResolvePartialID(ctx, store, id)
if err != nil {
@@ -162,7 +168,10 @@ var labelListCmd = &cobra.Command{
fmt.Fprintf(os.Stderr, "Error resolving issue ID %s: %v\n", args[0], err)
os.Exit(1)
}
issueID = string(resp.Data)
if err := json.Unmarshal(resp.Data, &issueID); err != nil {
fmt.Fprintf(os.Stderr, "Error unmarshaling resolved ID: %v\n", err)
os.Exit(1)
}
} else {
var err error
issueID, err = utils.ResolvePartialID(ctx, store, args[0])