Fix nil pointer dereference in bd show command (#80)

The show command was crashing with a nil pointer dereference when
accessing issue.CompactionLevel. This occurred due to two issues in
the daemon mode response handling:

1. The IssueDetails struct incorrectly embedded *types.Issue as a
   pointer, causing the JSON unmarshaling to leave it nil. Changed
   to embed types.Issue directly.

2. Missing null check for non-existent issues. The daemon returns
   null when an issue is not found, which wasn't handled properly.

Added explicit null checking before parsing the response to provide
a clear error message when issues don't exist.

Fixes panic when running: bd show <non-existent-id>
This commit is contained in:
Daan van Etten
2025-10-18 18:33:34 +02:00
committed by GitHub
parent 82d8750e1f
commit 86988fccf4

View File

@@ -1347,9 +1347,15 @@ var showCmd = &cobra.Command{
if jsonOutput {
fmt.Println(string(resp.Data))
} else {
// Check if issue exists (daemon returns null for non-existent issues)
if string(resp.Data) == "null" || len(resp.Data) == 0 {
fmt.Fprintf(os.Stderr, "Issue %s not found\n", args[0])
os.Exit(1)
}
// Parse response and use existing formatting code
type IssueDetails struct {
*types.Issue
types.Issue
Labels []string `json:"labels,omitempty"`
Dependencies []*types.Issue `json:"dependencies,omitempty"`
Dependents []*types.Issue `json:"dependents,omitempty"`
@@ -1359,7 +1365,7 @@ var showCmd = &cobra.Command{
fmt.Fprintf(os.Stderr, "Error parsing response: %v\n", err)
os.Exit(1)
}
issue := details.Issue
issue := &details.Issue
cyan := color.New(color.FgCyan).SprintFunc()