{"record":{"id":"c8dcddf050874cd9","repo":"gastownhall/beads","slug":"failed-to-remove-database-w","errorCode":null,"errorMessage":"failed to remove database: %w","messagePattern":"failed to remove database: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/doctor/fix/repo_fingerprint.go","lineNumber":164,"sourceCode":"\t\tconfirm, err := repoFingerprintReadLine()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to read confirmation: %w\", err)\n\t\t}\n\t\tconfirm = strings.TrimSpace(strings.ToLower(confirm))\n\t\tif confirm != \"y\" && confirm != \"yes\" {\n\t\t\tfmt.Println(\"  → Skipped (canceled)\")\n\t\t\treturn nil\n\t\t}\n\n\t\t// Remove database and reinitialize in-process\n\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\", \"\":","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/doctor/fix/repo_fingerprint.go#L146-L182","documentation":"For non-Dolt backends, option [2] deletes the SQLite-style database file with `os.Remove(dbPath)` (plus its `-wal`/`-shm` sidecars, whose errors are ignored). If removing the main database file fails for any reason other than 'does not exist', the error is wrapped as `failed to remove database: %w`. The reinitialize step is skipped so the old database is left intact.","triggerScenarios":"`os.Remove(dbPath)` returns a non-IsNotExist error on the configured database path: another process (bd daemon, SQLite client, IDE SQLite viewer) holds the file open in a way that blocks deletion, read-only filesystem, or insufficient write permission on `.beads`.","commonSituations":"bd daemon or another bd session keeping the SQLite DB open; database owned by a different user after running bd with sudo; database directory mounted read-only; backup/AV software holding a handle on the file (e.g. on network shares).","solutions":["Stop processes using the file (`bd daemon --stop`; check with `lsof .beads/<dbfile>`) and retry the fix.","Correct permissions/ownership of the `.beads` directory and database file.","Verify the filesystem is not read-only and there is free disk space; move the workspace off problematic network mounts if needed.","Inspect the unwrapped OS error (`errors.Unwrap`) to target the exact cause, or delete the file manually and re-bootstrap from `.beads/issues.jsonl`."],"exampleFix":"# before\nbd doctor --fix   # failed to remove database: permission denied\n# after\nsudo chown -R \"$USER\" .beads\nbd daemon --stop\nbd doctor --fix","handlingStrategy":"validation","validationCode":"dbPath := filepath.Join(beadsDir, \"dolt\") // per configfile config\nif handles := exec.Command(\"lsof\", \"+D\", dbPath).Run(); handles == nil {\n\treturn errors.New(\"database is open in another process; stop bd daemon first\")\n}\nif info, err := os.Stat(beadsDir); err == nil && info.Mode().Perm()&0200 == 0 {\n\treturn errors.New(\".beads not writable by current user\")\n}","typeGuard":null,"tryCatchPattern":"if err := fix.RepoFingerprint(path, true); err != nil && strings.Contains(err.Error(), \"failed to remove Dolt database\") {\n\tfmt.Fprintf(os.Stderr, \"close other bd processes / fix permissions, then retry: %v\\n\", err)\n\tos.Exit(1)\n}","preventionTips":["Stop the bd daemon and close other sessions before running doctor fixes that delete the database.","Run bd as the same user that owns .beads; avoid sudo-created ownership mismatches.","Keep the workspace on a local writable filesystem, not read-only or flaky network mounts.","Unwrap the error to read the raw OS errno (EBUSY/EACCES/EROFS) before retrying."],"tags":["go","filesystem","sqlite","os-remove","permissions"],"backgroundTag":"file-delete-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}