{"record":{"id":"e3eb93c83b920a48","repo":"gastownhall/beads","slug":"no-database-connection-available-s-e3eb93","errorCode":null,"errorMessage":"no database connection available (%s)","messagePattern":"no database connection available \\((.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/events.go","lineNumber":314,"sourceCode":"\t\treturn HandleErrorRespectJSON(\"pruning events journal: %v\", err)\n\t}\n\treturn reportEventsPruned(n, before)\n}\n\nfunc reportEventsPruned(n, before int64) error {\n\tif jsonOutput {\n\t\treturn outputJSON(map[string]any{\"pruned\": n})\n\t}\n\tfmt.Printf(\"Pruned %d events journal record(s) below seq %d\\n\", n, before)\n\treturn nil\n}\n\n// journalAccessor returns the active store's events-journal capability. The\n// embedded store and the server-mode store both provide it (via their own\n// transaction machinery); a backend that does not is reported as unsupported.\nfunc journalAccessor() (storage.EventsJournalAccessor, error) {\n\tif store == nil {\n\t\treturn nil, fmt.Errorf(\"no database connection available (%s)\", diagHint())\n\t}\n\tacc, ok := storage.UnwrapStore(store).(storage.EventsJournalAccessor)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"storage backend does not support the events journal\")\n\t}\n\treturn acc, nil\n}\n\n// readJournal reads records with seq greater than since from the active\n// storage seam. Proxied-server mode uses its transaction-bound UOW journal\n// capability; direct stores use EventsJournalAccessor.\n//\n// The projection onto the published envelope is eventsjournal.Records, the same\n// one GET /v0/beads/events serves from — see the note on eventsjournal.Record\n// for why there is exactly one.\nfunc readJournal(ctx context.Context, since int64, limit int) ([]eventsjournal.Record, error) {\n\tvar rows []storage.EventsJournalRow\n\tif usesProxiedServer() {","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/events.go#L296-L332","documentation":"journalAccessor resolves the active store's EventsJournalAccessor capability for `bd` events journal commands. It first requires a store to exist; when the package-level `store` is nil there is no database connection, so it fails with this message plus a diagnostic hint (diagHint()). It guards both readJournal and pruneJournal.","triggerScenarios":"Running a journal command (read/prune path) before any store is opened — e.g. outside a beads-initialized directory, with a failing `bd connect`/init, or in a context where store initialization was skipped (no-db-ops flag, missing database).","commonSituations":"Running `bd events` in a directory with no .beads database; BEADS_DIR pointing at an empty/wrong location; embedded mode init failed earlier and the error was swallowed.","solutions":["Run `bd init` (or `bd doctor`) in the directory to establish the database","Verify BEADS_DIR / current directory point at the beads repo that contains the database","Follow the diagHint() text printed with the error — it names the connection problem","Remove any --no-db style flags for commands that require store access"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if _, err := os.Stat(filepath.Join(beadsDir, \"db\")); err != nil {\n    return fmt.Errorf(\"no beads database in %s; run `bd init` first\", beadsDir)\n}","typeGuard":null,"tryCatchPattern":"if err := readJournalCmd(ctx); err != nil {\n    if strings.Contains(err.Error(), \"no database connection available\") {\n        // run `bd init` / `bd doctor`, then retry\n    }\n}","preventionTips":["Always initialize the beads database in the working directory before journal commands","Verify BEADS_DIR points at the intended repo","Run `bd doctor` when store-dependent commands fail at startup"],"tags":["cli","database","events-journal"],"backgroundTag":"no-database-connection","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}