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:
@@ -1347,9 +1347,15 @@ var showCmd = &cobra.Command{
|
|||||||
if jsonOutput {
|
if jsonOutput {
|
||||||
fmt.Println(string(resp.Data))
|
fmt.Println(string(resp.Data))
|
||||||
} else {
|
} 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
|
// Parse response and use existing formatting code
|
||||||
type IssueDetails struct {
|
type IssueDetails struct {
|
||||||
*types.Issue
|
types.Issue
|
||||||
Labels []string `json:"labels,omitempty"`
|
Labels []string `json:"labels,omitempty"`
|
||||||
Dependencies []*types.Issue `json:"dependencies,omitempty"`
|
Dependencies []*types.Issue `json:"dependencies,omitempty"`
|
||||||
Dependents []*types.Issue `json:"dependents,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)
|
fmt.Fprintf(os.Stderr, "Error parsing response: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
issue := details.Issue
|
issue := &details.Issue
|
||||||
|
|
||||||
cyan := color.New(color.FgCyan).SprintFunc()
|
cyan := color.New(color.FgCyan).SprintFunc()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user