gastownhall/beads · error

failed to remove Dolt database: %w

Error message

failed to remove Dolt database: %w

What it means

After the user confirms option [2], the Dolt backend path removes the database directory with `os.RemoveAll(dbPath)`. If the removal fails for a reason other than 'does not exist', the error is wrapped as `failed to remove Dolt database: %w`. This usually means something is holding the database open or the process lacks filesystem permissions — the reinitialize step is then not attempted.

Source

Thrown at cmd/bd/doctor/fix/repo_fingerprint.go:160

		isDolt := cfg.GetBackend() == configfile.BackendDolt

		// Confirm before destructive action
		fmt.Printf("  ⚠️  This will DELETE %s. Continue? [y/N]: ", dbPath)
		confirm, err := repoFingerprintReadLine()
		if err != nil {
			return fmt.Errorf("failed to read confirmation: %w", err)
		}
		confirm = strings.TrimSpace(strings.ToLower(confirm))
		if confirm != "y" && confirm != "yes" {
			fmt.Println("  → Skipped (canceled)")
			return nil
		}

		// Remove database and reinitialize in-process
		fmt.Printf("  → Removing %s...\n", dbPath)
		if isDolt {
			if err := os.RemoveAll(dbPath); err != nil && !os.IsNotExist(err) {
				return fmt.Errorf("failed to remove Dolt database: %w", err)
			}
		} else {
			if err := os.Remove(dbPath); err != nil && !os.IsNotExist(err) {
				return fmt.Errorf("failed to remove database: %w", err)
			}
			_ = os.Remove(dbPath + "-wal")
			_ = os.Remove(dbPath + "-shm")
		}

		// Reinitialize by creating a new store (auto-bootstraps from JSONL)
		fmt.Println("  → Reinitializing database from JSONL...")
		ctx := context.Background()
		store, err := dolt.NewFromConfig(ctx, beadsDir)
		if err != nil {
			return fmt.Errorf("failed to initialize database: %w", err)
		}
		defer func() { _ = store.Close() }()

View on GitHub (pinned to 71377f2769)

Solutions

  1. Stop all bd processes holding the database (`bd daemon --stop`, close other sessions/terminals) and retry.
  2. Check and fix permissions on the `.beads` directory and its parent (`ls -la .beads`, `chown`/`chmod` as needed).
  3. Inspect the wrapped error via `errors.Unwrap` for the exact OS reason (EBUSY, EACCES, EROFS) and address it.
  4. Remove the directory manually once nothing holds it, then re-run the fix or let bd re-bootstrap from `.beads/issues.jsonl`.

Example fix

// before: fix fails while daemon holds the database
bd doctor --fix            // fails: failed to remove Dolt database: device or resource busy
// after
bd daemon --stop
bd doctor --fix            # removal and reinit succeed
Defensive patterns

Strategy: try-catch

Validate before calling

// Ensure every prompt can be answered before choosing option 2
answers := "2\ny\n"
cmd := exec.Command("bd", "doctor", "--fix")
cmd.Stdin = strings.NewReader(answers) // two lines: choice + confirmation
cmd.Stdout = os.Stdout

Type guard

if errors.Is(err, io.EOF) {
	// confirmation input never arrived; treat as canceled, database untouched
}

Try / catch

if err := fix.RepoFingerprint(path, false); err != nil {
	var wrapped interface{ Unwrap() error }
	if errors.As(err, &wrapped) && errors.Is(wrapped, io.EOF) {
		fmt.Println("confirmation not received; destructive action safely skipped")
	} else if err != nil {
		log.Fatal(err)
	}
}

Prevention

When it happens

Trigger: `os.RemoveAll(dbPath)` returns a non-IsNotExist error: the `.beads` Dolt database directory is locked/open by another `bd` process or Dolt server, the directory or a file inside is read-only, or the user lacks write permission on the parent directory.

Common situations: A `bd daemon` or another bd session still has the Dolt database open; running the fix without sufficient permissions (e.g. database owned by another user); filesystem mounted read-only; NFS/network mounts with stale locks.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/c968b2a95da1fc38. Report an issue: GitHub.