{"record":{"id":"8e5f51f06fcea839","repo":"gastownhall/beads","slug":"no-database-connection-8e5f51","errorCode":null,"errorMessage":"no database connection","messagePattern":"no database connection","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/template.go","lineNumber":85,"sourceCode":"\tAttachToID    string               // Molecule ID to attach spawned root to\n\tAttachDepType types.DependencyType // Dependency type for the attachment\n\n\t// RootOnly: if true, only create the root issue (no child step issues).\n\t// Used by patrol wisps where steps are inlined at prime time, not tracked as beads.\n\tRootOnly bool\n}\n\n// bondedIDPattern validates bonded IDs (alphanumeric, dash, underscore, dot)\nvar bondedIDPattern = regexp.MustCompile(`^[a-zA-Z0-9_.-]+$`)\n\n// =============================================================================\n// Beads Template Functions\n// =============================================================================\n\n// loadTemplateSubgraph loads a template epic and all its descendants\nfunc loadTemplateSubgraph(ctx context.Context, s molReader, templateID string) (*TemplateSubgraph, error) {\n\tif s == nil {\n\t\treturn nil, fmt.Errorf(\"no database connection\")\n\t}\n\n\t// Get the root issue\n\troot, err := s.GetIssue(ctx, templateID)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get template: %w\", err)\n\t}\n\tif root == nil {\n\t\treturn nil, fmt.Errorf(\"template %s not found\", templateID)\n\t}\n\n\tsubgraph := &TemplateSubgraph{\n\t\tRoot:     root,\n\t\tIssues:   []*types.Issue{root},\n\t\tIssueMap: map[string]*types.Issue{root.ID: root},\n\t}\n\n\t// Recursively load all children (with cycle detection, GH#2719)","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/template.go#L67-L103","documentation":"loadTemplateSubgraph requires a non-nil store implementing molReader before it can load a template epic and its descendants. If the caller passes a nil store, this guard error is thrown. It signals a programming/setup problem: the template operation ran without any database connection wired in.","triggerScenarios":"Any template command path (deleteProtoSubgraph, bondProtoMolWithSubgraph, bondProtoMolAttachInto, resolveOrCookToSubgraph, burnMultipleMolecules, burnWispMolecule) reaching loadTemplateSubgraph with s == nil — i.e. the store failed to open earlier or was not propagated to the template layer.","commonSituations":"Database unavailable earlier in the command but the error was swallowed or defaulted to nil; calling template helper APIs programmatically without opening the store first; running before bd init in a workspace.","solutions":["Ensure the beads database is initialized and open before running template commands (bd init; run from repo root)","Fix the earlier store-open failure — check for an earlier 'database not available' error in output","If calling the helper programmatically, pass a valid molReader store instead of nil"],"exampleFix":"// before\nvar s molReader // nil when store open failed but error ignored\nsub, err := loadTemplateSubgraph(ctx, s, tplID)\n// after\ns, err := openStore(ctx)\nif err != nil { return err }\nsub, err := loadTemplateSubgraph(ctx, s, tplID)","handlingStrategy":"validation","validationCode":"s, err := openStore(ctx)\nif err != nil {\n    return fmt.Errorf(\"cannot open beads store: %w\", err)\n}\nsub, err := loadTemplateSubgraph(ctx, s, templateID)","typeGuard":"// guard before calling template helpers\nfunc ensureStore(s molReader) (molReader, error) {\n    if s == nil {\n        return nil, fmt.Errorf(\"store must be opened before template operations\")\n    }\n    return s, nil\n}","tryCatchPattern":"sub, err := loadTemplateSubgraph(ctx, store, tplID)\nif err != nil && strings.Contains(err.Error(), \"no database connection\") {\n    return fmt.Errorf(\"template operation skipped: store not initialized; run bd init first\")\n}","preventionTips":["Always propagate the store-open error instead of defaulting the store to nil","Run template commands only inside an initialized beads workspace","Add a nil-store check at command entry points before invoking template helpers"],"tags":["templates","database","nil-guard","cli"],"backgroundTag":"database-not-available","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}