gastownhall/beads · critical

no database connection

Error message

no database connection

What it means

Guard in cookFormula: it requires a non-nil storage.DoltStorage because cooking persists a proto bead and its dependencies to the Dolt database. A nil storage means the command has no open database connection, so cooking cannot proceed.

Source

Thrown at cmd/bd/cook.go:849

	if vars != nil {
		subgraph.VarDefs = make(map[string]formula.VarDef)
		for k, v := range vars {
			if v != nil {
				subgraph.VarDefs[k] = *v
			}
		}
	}
	// Attach recommended phase and pour flag from formula
	subgraph.Phase = f.Phase
	subgraph.Pour = f.Pour
	return subgraph, nil
}

// cookFormula creates a proto bead from a resolved formula.
// protoID is the final ID for the proto (may include a prefix).
func cookFormula(ctx context.Context, s storage.DoltStorage, f *formula.Formula, protoID string) (*cookFormulaResult, error) {
	if s == nil {
		return nil, fmt.Errorf("no database connection")
	}

	// Map step ID -> created issue ID
	idMapping := make(map[string]string)

	// Collect all issues and dependencies
	var issues []*types.Issue
	var deps []*types.Dependency
	var labels []struct{ issueID, label string }

	// Determine root title: use {{title}} placeholder if the variable is defined,
	// otherwise fall back to formula name (GH#852)
	rootTitle := f.Formula
	if _, hasTitle := f.Vars["title"]; hasTitle {
		rootTitle = "{{title}}"
	}

	// Determine root description: use {{desc}} placeholder if the variable is defined,

View on GitHub (pinned to 71377f2769)

Solutions

  1. Run `bd init` in the repository (or ensure .beads database exists) before cooking with persistence
  2. Open the database before calling cook/persist (bd normally does this; check for earlier swallowed open errors)
  3. Run the command from the repository root so the bd database is discovered
  4. If embedding bd programmatically, pass a valid storage.DoltStorage instead of nil
Defensive patterns

Strategy: validation

Validate before calling

// Before requesting persistent cook, ensure the store is open
if store == nil {
    return fmt.Errorf("cannot cook --persist: no database; run 'bd init' first")
}
if _, err := os.Stat(filepath.Join(cwd, ".beads")); err != nil {
    return fmt.Errorf("not in a bd repository: %w", err)
}

Type guard

func hasStore(s storage.DoltStorage) bool { return s != nil }

Try / catch

result, err := cookFormula(ctx, store, f, protoID)
if err != nil && err.Error() == "no database connection" {
    // open the database (bd init / store open) then retry once
    store, err = openStore(ctx)
    if err == nil { result, err = cookFormula(ctx, store, f, protoID) }
}

Prevention

When it happens

Trigger: cookFormula called (via persistCookFormula) with s == nil — i.e. the command ran without an initialized/open Dolt database handle, such as when persistence is requested but the store was never opened or was closed.

Common situations: Running `bd cook --persist` outside an initialized bd repository (no .beads database); database open failed earlier but the nil handle was passed through; daemon/server mode where the proxied server has no DB configured.

Related errors


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