fix: handle bd --no-daemon exit code 0 bug on not-found (#339)

When bd --no-daemon show <id> does not find an issue, it incorrectly exits
with code 0 (success) but writes the error to stderr and leaves stdout empty.
This causes JSON parse failures throughout gt when code tries to unmarshal
the empty stdout.

This PR handles the bug defensively in all affected code paths:
- beads.go run(): Detect empty stdout + non-empty stderr as error
- beads.go wrapError(): Add 'no issue found' to ErrNotFound patterns
- sling.go: Check len(out) == 0 in multiple functions
- convoy.go getIssueDetails(): Check stdout.Len() == 0
- prime_molecule.go: Check stdout.Len() == 0

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
gastown/crew/joe
2026-01-11 18:37:01 -08:00
committed by Steve Yegge
parent b9025379b7
commit d126c967a0
4 changed files with 40 additions and 4 deletions

View File

@@ -151,6 +151,13 @@ func (b *Beads) run(args ...string) ([]byte, error) {
return nil, b.wrapError(err, stderr.String(), args)
}
// Handle bd --no-daemon exit code 0 bug: when issue not found,
// --no-daemon exits 0 but writes error to stderr with empty stdout.
// Detect this case and treat as error to avoid JSON parse failures.
if stdout.Len() == 0 && stderr.Len() > 0 {
return nil, b.wrapError(fmt.Errorf("command produced no output"), stderr.String(), args)
}
return stdout.Bytes(), nil
}
@@ -174,7 +181,9 @@ func (b *Beads) wrapError(err error, stderr string, args []string) error {
}
// ErrNotFound is widely used for issue lookups - acceptable exception
if strings.Contains(stderr, "not found") || strings.Contains(stderr, "Issue not found") {
// Match various "not found" error patterns from bd
if strings.Contains(stderr, "not found") || strings.Contains(stderr, "Issue not found") ||
strings.Contains(stderr, "no issue found") {
return ErrNotFound
}