{"record":{"id":"93768f63b6c3ad61","repo":"gastownhall/beads","slug":"failed-to-initialize-database-w","errorCode":null,"errorMessage":"failed to initialize database: %w","messagePattern":"failed to initialize database: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"cmd/bd/doctor/fix/repo_fingerprint.go","lineNumber":175,"sourceCode":"\t\tfmt.Printf(\"  → Removing %s...\\n\", dbPath)\n\t\tif isDolt {\n\t\t\tif err := os.RemoveAll(dbPath); err != nil && !os.IsNotExist(err) {\n\t\t\t\treturn fmt.Errorf(\"failed to remove Dolt database: %w\", err)\n\t\t\t}\n\t\t} else {\n\t\t\tif err := os.Remove(dbPath); err != nil && !os.IsNotExist(err) {\n\t\t\t\treturn fmt.Errorf(\"failed to remove database: %w\", err)\n\t\t\t}\n\t\t\t_ = os.Remove(dbPath + \"-wal\")\n\t\t\t_ = os.Remove(dbPath + \"-shm\")\n\t\t}\n\n\t\t// Reinitialize by creating a new store (auto-bootstraps from JSONL)\n\t\tfmt.Println(\"  → Reinitializing database from JSONL...\")\n\t\tctx := context.Background()\n\t\tstore, err := dolt.NewFromConfig(ctx, beadsDir)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to initialize database: %w\", err)\n\t\t}\n\t\tdefer func() { _ = store.Close() }()\n\n\t\tfmt.Println(\"  ✓ Database reinitialized\")\n\t\treturn nil\n\n\tcase \"s\", \"\":\n\t\tfmt.Println(\"  → Skipped\")\n\t\treturn nil\n\n\tdefault:\n\t\tfmt.Printf(\"  → Unrecognized input '%s', skipping\\n\", response)\n\t\treturn nil\n\t}\n}\n","sourceCodeStart":157,"sourceCodeEnd":191,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/doctor/fix/repo_fingerprint.go#L157-L191","documentation":"After deleting the old database in option [2], the fix re-creates it in-process via `dolt.NewFromConfig(ctx, beadsDir)`, which initializes a fresh Dolt store and auto-bootstraps issues from `.beads/issues.jsonl`. If store creation or bootstrap fails, the error is wrapped as `failed to initialize database: %w`. At this point the old database is already removed, so recovery depends on the JSONL export.","triggerScenarios":"`dolt.NewFromConfig` fails right after the old DB was deleted: corrupt or missing `.beads/issues.jsonl` to bootstrap from, `.beads` not writable, disk full, corrupted Dolt config in `.beads`, or leftover Dolt metadata/locks confusing initialization.","commonSituations":"User deleted the database with a stale or never-synced issues.jsonl (data loss risk); .beads directory made read-only mid-flow; interrupted previous init leaving partial Dolt files; out-of-disk during re-initialization.","solutions":["Check `.beads/issues.jsonl` exists and is valid JSONL — it is the bootstrap source for the new database.","Free disk space and ensure `.beads` is writable, then re-run the fix (or any bd command that re-initializes the store).","Inspect the wrapped error from `dolt.NewFromConfig` for the precise cause (config parse, IO, bootstrap) and fix accordingly.","If the JSONL is stale, restore the database from git history or a Dolt remote (`bd dolt pull`) instead of reinitializing."],"exampleFix":"# before: stale/missing export leaves an empty or failing reinit\nls .beads/issues.jsonl   # missing or truncated\n# after: restore the export from git, then retry\ngit checkout -- .beads/issues.jsonl\nbd doctor --fix --yes","handlingStrategy":"fallback","validationCode":"jsonl := filepath.Join(beadsDir, \"issues.jsonl\")\ninfo, err := os.Stat(jsonl)\nif err != nil {\n\treturn fmt.Errorf(\"bootstrap export missing: %w\", err)\n}\nif info.Size() == 0 {\n\treturn errors.New(\"issues.jsonl is empty; restore from git or dolt remote before reinit\")\n}\nif avail := freeDisk(beadsDir); avail < 64*1024*1024 {\n\treturn errors.New(\"insufficient disk space for reinitialization\")\n}","typeGuard":null,"tryCatchPattern":"if err := fix.RepoFingerprint(path, true); err != nil && strings.Contains(err.Error(), \"failed to initialize database\") {\n\t// old DB is gone; recover from export or remote\n\t_ = exec.Command(\"git\", \"checkout\", \"--\", \".beads/issues.jsonl\").Run()\n\t_ = exec.Command(\"bd\", \"dolt\", \"pull\").Run()\n\t// retry initialization before giving up\n\tif err2 := fix.RepoFingerprint(path, true); err2 != nil {\n\t\tlog.Fatalf(\"reinit failed after recovery attempt: %v\", err2)\n\t}\n}","preventionTips":["Always keep `.beads/issues.jsonl` committed and current before running destructive fixes.","Run `bd dolt push` so a remote copy exists as a recovery path before deleting the database.","Verify free disk space and .beads writability before choosing option [2].","Take a backup (`cp -a .beads .beads.bak`) before any fix that deletes the database."],"tags":["go","dolt","database-init","jsonl","bootstrap"],"backgroundTag":"database-init-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}