{"record":{"id":"2aa0781199948b83","repo":"gastownhall/beads","slug":"no-database-connection-2aa078","errorCode":null,"errorMessage":"no database connection","messagePattern":"no database connection","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/mol_squash.go","lineNumber":243,"sourceCode":"\t\t\t}\n\t\t\tsb.WriteString(fmt.Sprintf(\"   %s\\n\", desc))\n\t\t}\n\t\tif child.CloseReason != \"\" {\n\t\t\tsb.WriteString(fmt.Sprintf(\"   *Outcome: %s*\\n\", child.CloseReason))\n\t\t}\n\t\tsb.WriteString(\"\\n\")\n\t}\n\n\treturn sb.String()\n}\n\n// squashMolecule performs the squash operation\n// If summary is provided (non-empty), it's used as the digest content.\n// Otherwise, generateDigest() creates a basic concatenation.\n// This enables agents to provide AI-generated summaries while keeping bd as a pure tool.\nfunc squashMolecule(ctx context.Context, s storage.DoltStorage, root *types.Issue, children []*types.Issue, keepChildren bool, summary string, actorName string) (*SquashResult, error) {\n\tif s == nil {\n\t\treturn nil, fmt.Errorf(\"no database connection\")\n\t}\n\n\tvar result *SquashResult\n\terr := transact(ctx, s, fmt.Sprintf(\"bd: squash molecule %s\", root.ID), func(tx storage.Transaction) error {\n\t\tr, err := squashMoleculeInto(ctx, storeMolWriter{DoltStorage: s, tx: tx}, root, children, keepChildren, summary, actorName)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tresult = r\n\t\treturn nil\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn result, nil\n}\n\nfunc squashMoleculeInto(ctx context.Context, w molWriter, root *types.Issue, children []*types.Issue, keepChildren bool, summary string, actorName string) (*SquashResult, error) {","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/mol_squash.go#L225-L261","documentation":"squashMolecule requires a non-nil DoltStorage handle. If called with nil storage it returns 'no database connection'. This is a guard against invoking squash without an open database session (e.g., in tests or before initialization).","triggerScenarios":"Calling squashMolecule programmatically (or via runMolSquash paths) before storage initialization succeeds, or when database open/connect was skipped or failed silently upstream.","commonSituations":"Running bd mol squash in an environment with no .beads database initialized; embedded mode not set up; tests passing a nil storage stub.","solutions":["Ensure bd init (or equivalent) created the database before running bd mol squash","Check that storage opened successfully earlier in the command; fix any init errors surfaced there","In tests/automation, construct and pass a real DoltStorage instance instead of nil"],"exampleFix":"// before\nvar s storage.DoltStorage // nil\nresult, err := squashMolecule(ctx, s, root, children, true, \"\", actor)\n// after\ns, err := storage.Open(ctx)\nif err != nil { return err }\nresult, err := squashMolecule(ctx, s, root, children, true, \"\", actor)","handlingStrategy":"validation","validationCode":"if s == nil {\n    return fmt.Errorf(\"no database connection: run bd init first\")\n}","typeGuard":"func hasStorage(s storage.DoltStorage) bool { return s != nil }","tryCatchPattern":"result, err := squashMolecule(ctx, s, root, children, keep, summary, actor)\nif err != nil {\n    if err.Error() == \"no database connection\" {\n        return fmt.Errorf(\"open the database (bd init / storage.Open) before squash\")\n    }\n    return err\n}","preventionTips":["Always call storage.Open and check its error before molecule commands","Initialize the repo database (bd init) before scripting bd mol commands","In tests, never pass nil storage; use a real or in-memory DoltStorage"],"tags":["go","storage","dolt","initialization"],"backgroundTag":"no-database-connection","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}