Fix bd delete panic when daemon is running

Closes bd-155

When daemon is running, store is nil because PersistentPreRun returns
early after connecting to daemon. The delete command (both single and
batch) now falls back to direct storage access when store is nil,
following the pattern used by other commands like ready and blocked.

Amp-Thread-ID: https://ampcode.com/threads/T-4e1ac6f1-7465-442a-a385-adaa98b539ad
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Steve Yegge
2025-10-17 22:06:21 -07:00
parent c17174b80a
commit 63c538616d

View File

@@ -86,6 +86,17 @@ Force: Delete and orphan dependents
// Single issue deletion (legacy behavior)
issueID := issueIDs[0]
// If daemon is running but doesn't support this command, use direct storage
if daemonClient != nil && store == nil {
var err error
store, err = sqlite.New(dbPath)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: failed to open database: %v\n", err)
os.Exit(1)
}
defer store.Close()
}
ctx := context.Background()
// Get the issue to be deleted
@@ -358,6 +369,17 @@ func removeIssueFromJSONL(issueID string) error {
// deleteBatch handles deletion of multiple issues
func deleteBatch(cmd *cobra.Command, issueIDs []string, force bool, dryRun bool, cascade bool) {
// If daemon is running but doesn't support this command, use direct storage
if daemonClient != nil && store == nil {
var err error
store, err = sqlite.New(dbPath)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: failed to open database: %v\n", err)
os.Exit(1)
}
defer store.Close()
}
ctx := context.Background()
// Type assert to SQLite storage