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

@@ -3,6 +3,7 @@ package main
import (
"context"
"encoding/json"
"fmt"
"os"
"strings"
@@ -38,7 +39,10 @@ var depAddCmd = &cobra.Command{
fmt.Fprintf(os.Stderr, "Error resolving issue ID %s: %v\n", args[0], err)
os.Exit(1)
}
fromID = string(resp.Data)
if err := json.Unmarshal(resp.Data, &fromID); err != nil {
fmt.Fprintf(os.Stderr, "Error unmarshaling resolved ID: %v\n", err)
os.Exit(1)
}
resolveArgs = &rpc.ResolveIDArgs{ID: args[1]}
resp, err = daemonClient.ResolveID(resolveArgs)
@@ -46,7 +50,10 @@ var depAddCmd = &cobra.Command{
fmt.Fprintf(os.Stderr, "Error resolving dependency ID %s: %v\n", args[1], err)
os.Exit(1)
}
toID = string(resp.Data)
if err := json.Unmarshal(resp.Data, &toID); err != nil {
fmt.Fprintf(os.Stderr, "Error unmarshaling resolved ID: %v\n", err)
os.Exit(1)
}
} else {
var err error
fromID, err = utils.ResolvePartialID(ctx, store, args[0])
@@ -159,7 +166,10 @@ var depRemoveCmd = &cobra.Command{
fmt.Fprintf(os.Stderr, "Error resolving issue ID %s: %v\n", args[0], err)
os.Exit(1)
}
fromID = string(resp.Data)
if err := json.Unmarshal(resp.Data, &fromID); err != nil {
fmt.Fprintf(os.Stderr, "Error unmarshaling resolved ID: %v\n", err)
os.Exit(1)
}
resolveArgs = &rpc.ResolveIDArgs{ID: args[1]}
resp, err = daemonClient.ResolveID(resolveArgs)
@@ -167,7 +177,10 @@ var depRemoveCmd = &cobra.Command{
fmt.Fprintf(os.Stderr, "Error resolving dependency ID %s: %v\n", args[1], err)
os.Exit(1)
}
toID = string(resp.Data)
if err := json.Unmarshal(resp.Data, &toID); err != nil {
fmt.Fprintf(os.Stderr, "Error unmarshaling resolved ID: %v\n", err)
os.Exit(1)
}
} else {
var err error
fromID, err = utils.ResolvePartialID(ctx, store, args[0])
@@ -250,7 +263,10 @@ var depTreeCmd = &cobra.Command{
fmt.Fprintf(os.Stderr, "Error resolving issue ID %s: %v\n", args[0], err)
os.Exit(1)
}
fullID = string(resp.Data)
if err := json.Unmarshal(resp.Data, &fullID); err != nil {
fmt.Fprintf(os.Stderr, "Error unmarshaling resolved ID: %v\n", err)
os.Exit(1)
}
} else {
var err error
fullID, err = utils.ResolvePartialID(ctx, store, args[0])

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])

View File

@@ -30,7 +30,12 @@ This is more explicit than 'bd update --status open' and emits a Reopened event.
fmt.Fprintf(os.Stderr, "Error resolving ID %s: %v\n", id, err)
os.Exit(1)
}
resolvedIDs = append(resolvedIDs, string(resp.Data))
var resolvedID string
if err := json.Unmarshal(resp.Data, &resolvedID); err != nil {
fmt.Fprintf(os.Stderr, "Error unmarshaling resolved ID: %v\n", err)
os.Exit(1)
}
resolvedIDs = append(resolvedIDs, resolvedID)
}
} else {
var err error

View File

@@ -31,7 +31,12 @@ var showCmd = &cobra.Command{
fmt.Fprintf(os.Stderr, "Error resolving ID %s: %v\n", id, err)
os.Exit(1)
}
resolvedIDs = append(resolvedIDs, string(resp.Data))
var resolvedID string
if err := json.Unmarshal(resp.Data, &resolvedID); err != nil {
fmt.Fprintf(os.Stderr, "Error unmarshaling resolved ID: %v\n", err)
os.Exit(1)
}
resolvedIDs = append(resolvedIDs, resolvedID)
}
} else {
// In direct mode, resolve via storage
@@ -369,7 +374,12 @@ var updateCmd = &cobra.Command{
fmt.Fprintf(os.Stderr, "Error resolving ID %s: %v\n", id, err)
os.Exit(1)
}
resolvedIDs = append(resolvedIDs, string(resp.Data))
var resolvedID string
if err := json.Unmarshal(resp.Data, &resolvedID); err != nil {
fmt.Fprintf(os.Stderr, "Error unmarshaling resolved ID: %v\n", err)
os.Exit(1)
}
resolvedIDs = append(resolvedIDs, resolvedID)
}
} else {
var err error
@@ -650,7 +660,12 @@ var closeCmd = &cobra.Command{
fmt.Fprintf(os.Stderr, "Error resolving ID %s: %v\n", id, err)
os.Exit(1)
}
resolvedIDs = append(resolvedIDs, string(resp.Data))
var resolvedID string
if err := json.Unmarshal(resp.Data, &resolvedID); err != nil {
fmt.Fprintf(os.Stderr, "Error unmarshaling resolved ID: %v\n", err)
os.Exit(1)
}
resolvedIDs = append(resolvedIDs, resolvedID)
}
} else {
var err error