{"record":{"id":"ffb4e9806cfe4674","repo":"gastownhall/beads","slug":"w-hint-run-bd-init-to-create-a-database-in-th","errorCode":null,"errorMessage":"%w.\nHint: run 'bd init' to create a database in the current directory","messagePattern":"%w\\.\nHint: run 'bd init' to create a database in the current directory","errorType":"exception","errorClass":"ErrNoBeadsDatabase","httpStatus":null,"severity":"error","filePath":"cmd/bd/direct_mode.go","lineNumber":43,"sourceCode":"\treturn ensureStoreActiveWithContext(getRootContext())\n}\n\nfunc ensureStoreActiveWithContext(ctx context.Context) error {\n\tif ctx == nil {\n\t\tctx = context.Background()\n\t}\n\n\tlockStore()\n\tactive := isStoreActive() && getStore() != nil\n\tunlockStore()\n\tif active {\n\t\treturn nil\n\t}\n\n\t// Find the .beads directory\n\tbeadsDir := beads.FindBeadsDir()\n\tif beadsDir == \"\" {\n\t\treturn fmt.Errorf(\"%w.\\n\"+\n\t\t\t\"Hint: run 'bd init' to create a database in the current directory\", ErrNoBeadsDatabase)\n\t}\n\n\t// Use the factory to create the appropriate backend\n\t// based on metadata.json configuration and build tags\n\tstore, err := newDoltStoreFromConfig(ctx, beadsDir)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to open database: %w\\nHint: %s\", err, diagHint())\n\t}\n\n\t// Update the database path for compatibility with code that expects it\n\tif dbPath := beads.FindDatabasePath(); dbPath != \"\" {\n\t\tsetDBPath(dbPath)\n\t}\n\n\tlockStore()\n\tsetStore(store)\n\tsetStoreActive(true)","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/direct_mode.go#L25-L61","documentation":"ensureStoreActiveWithContext locates the .beads directory before opening the storage backend. If beads.FindBeadsDir() finds nothing — no .beads directory in the current directory or any ancestor — it returns ErrNoBeadsDatabase wrapped with a hint to run 'bd init'. Callers distinguish this via errors.Is(err, ErrNoBeadsDatabase): it means 'no workspace at all', not 'workspace broken'.","triggerScenarios":"Running any direct-storage bd command (that calls ensureStoreActive) outside a beads workspace: no .beads directory exists in the current directory or any parent, and store is not already active.","commonSituations":"Running bd in a fresh repo before initialization; running from a directory outside the repo (bd does not cross into the right ancestor); deleted or renamed .beads directory; CI jobs checking out only part of the repo.","solutions":["Run 'bd init' in the project root to create the .beads database.","cd into the repository/workspace root (or a subdirectory of it) before running bd commands.","If .beads was deleted, restore it from git or re-init and re-import from issues.jsonl.","Programmatic callers: match with errors.Is(err, ErrNoBeadsDatabase) to handle this case distinctly."],"exampleFix":"// before (wrong directory)\n/tmp$ bd list\n// after\n/tmp/myproject$ bd init && bd list","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(\".beads\"); os.IsNotExist(err) {\n    return fmt.Errorf(\"not a beads workspace: run 'bd init'\")\n}","typeGuard":null,"tryCatchPattern":"if err := ensureStoreActive(); err != nil {\n    if errors.Is(err, ErrNoBeadsDatabase) {\n        return initWorkspace() // or prompt the user\n    }\n    return err\n}","preventionTips":["Always run 'bd init' after cloning a project without .beads.","Run bd commands from the repository root or its subdirectories.","Commit .beads/ (or its export) so workspaces are reproducible.","In scripts, match errors.Is(err, ErrNoBeadsDatabase) to auto-init or exit clearly."],"tags":["go","workspace","initialization","cli"],"backgroundTag":"no-beads-database-found","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}