gastownhall/beads · error

no database available

Error message

no database available

What it means

getIssueProviderFn creates an IssueProvider backed by the global Dolt store. If the global store variable is nil (no database open in this process), it returns 'no database available'. It is a guard so orphan-search callers never run without a backing store.

Source

Thrown at cmd/bd/orphans.go:181

	// may belong to a different project (GH#2469).
	if yamlPrefix := config.GetString("issue-prefix"); yamlPrefix != "" {
		return yamlPrefix
	}
	ctx := context.Background()
	prefix, err := store.GetConfig(ctx, "issue_prefix")
	if err != nil || prefix == "" {
		return "bd"
	}
	return prefix
}

// getIssueProviderFn is the function used to create an IssueProvider.
// It is a variable so tests can substitute a mock without needing a real store.
var getIssueProviderFn = func(labels, labelsAny []string) (types.IssueProvider, func(), error) {
	if store != nil {
		return &doltStoreProvider{labels: labels, labelsAny: labelsAny}, func() {}, nil
	}
	return nil, nil, fmt.Errorf("no database available")
}

// getIssueProvider returns an IssueProvider backed by the global Dolt store.
// labels and labelsAny are passed through to SearchIssues for label filtering.
func getIssueProvider(labels, labelsAny []string) (types.IssueProvider, func(), error) {
	return getIssueProviderFn(labels, labelsAny)
}

// findOrphanedIssues wraps the shared doctor package function and converts to output format.
// It respects the --db flag for cross-repo orphan detection.
// labels and labelsAny are passed to the issue provider to restrict which issues are considered.
func findOrphanedIssues(path string, labels, labelsAny []string) ([]orphanIssueOutput, error) {
	provider, cleanup, err := getIssueProvider(labels, labelsAny)
	if err != nil {
		return nil, fmt.Errorf("unable to find orphaned issues: %w", err)
	}
	defer cleanup()

View on GitHub (pinned to 71377f2769)

Solutions

  1. Run the command from a directory with an initialized beads DB, or pass the correct --db path.
  2. Initialize a database with 'bd init' if none exists.
  3. Run 'bd doctor' to check store connectivity and initialization errors.
  4. For proxied/server usage, ensure the server-side store is opened before handling orphan requests.

Example fix

// before
bd orphans                      # run outside repo -> no database available
// after
cd /path/to/repo && bd orphans  # or: bd orphans --db /path/to/.beads
Defensive patterns

Strategy: validation

Validate before calling

if store == nil {
    return errors.New("no database available; run bd init or pass --db")
}
if _, err := os.Stat(filepath.Join(path, ".beads")); err != nil {
    return fmt.Errorf("not a beads repo: %w", err)
}

Try / catch

provider, cleanup, err := getIssueProvider(labels, labelsAny)
if err != nil {
    if strings.Contains(err.Error(), "no database available") {
        // open/init the store, then retry
    }
    return err
}
defer cleanup()

Prevention

When it happens

Trigger: Calling getIssueProvider (via findOrphanedIssues, bd orphans / bd doctor conventions orphans) when the global `store` is nil — e.g. no DB was opened, wrong --db path, or the store failed to initialize earlier.

Common situations: Running 'bd orphans' outside a beads repository (no .beads database), pointing --db at a nonexistent path, or invoking the command in a context where store initialization was skipped (proxied/server mode misconfiguration).

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/f22ace9915aef9d4. Report an issue: GitHub.