fix(utils): prevent nil pointer panic in ResolvePartialID (#1132)

Add nil check at start of ResolvePartialID to return a proper error
instead of panicking when storage interface is nil.

Root cause: When bd refile (or other commands) is called with a nil
storage, calling store.SearchIssues() panics with SIGSEGV. This can
happen when routing fails to initialize storage properly.

Now returns: "cannot resolve issue ID <id>: storage is nil"

Fixes: bd-7ypor

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Nicolas Suzor
2026-01-17 18:00:56 +10:00
committed by GitHub
parent aee86dfae2
commit c8187137f5
2 changed files with 19 additions and 0 deletions

View File

@@ -37,6 +37,10 @@ func ParseIssueID(input string, prefix string) string {
// - No issue found matching the ID
// - Multiple issues match (ambiguous prefix)
func ResolvePartialID(ctx context.Context, store storage.Storage, input string) (string, error) {
if store == nil {
return "", fmt.Errorf("cannot resolve issue ID %q: storage is nil", input)
}
// Fast path: Use SearchIssues with exact ID filter (GH#942).
// This uses the same query path as "bd list --id", ensuring consistency.
// Previously we used GetIssue which could fail in cases where SearchIssues