can1357/oh-my-pi · warning · ValueError

Cannot delete 'default' bank without force=True

Error message

Cannot delete 'default' bank without force=True

What it means

The built-in `default` bank is protected: `deleteBank()` refuses to remove it unless `force` is explicitly true. This prevents accidentally wiping the bank that all unqualified operations use.

Source

Thrown at packages/mnemopi/src/core/banks.ts:45

	constructor(dataDir?: string) {
		this.dataDir = dataDir ?? configuredDataDir();
		this.banksDir = join(this.dataDir, "banks");
		mkdirSync(this.banksDir, { recursive: true });
	}

	createBank(name: string): string {
		this.validateName(name);
		const bankDir = join(this.banksDir, name);
		if (existsSync(bankDir)) throw new ValueError(`Bank '${name}' already exists`);
		mkdirSync(bankDir, { recursive: true });
		const dbPath = join(bankDir, DB_FILENAME);
		const db = openDatabase(dbPath);
		closeQuietly(db);
		return dbPath;
	}
	deleteBank(name: string, force = false): boolean {
		this.validateName(name);
		if (name === "default" && !force) throw new ValueError("Cannot delete 'default' bank without force=True");
		const bankDir = join(this.banksDir, name);
		if (!existsSync(bankDir)) return false;
		rmSync(bankDir, { recursive: true, force: true });
		return true;
	}
	listBanks(): string[] {
		const banks: string[] = ["default"];
		if (existsSync(this.banksDir)) {
			for (const entry of readdirSync(this.banksDir, { withFileTypes: true })) {
				if (entry.isDirectory() && entry.name !== "default") banks.push(entry.name);
			}
		}
		return banks.sort();
	}
	bankExists(name: string): boolean {
		if (name === "default") return true;
		return existsSync(join(this.banksDir, name));
	}

View on GitHub (pinned to 9690622007)

Solutions

  1. Pass `force = true` if you really intend to delete it: `deleteBank("default", true)`.
  2. Skip the default bank in cleanup loops (`if (name === "default") continue;`).
  3. Instead of deleting, clear its contents via the annotations API if the goal is reset-without-removal.
  4. Back up the bank directory before forcing deletion.

Example fix

// before
banks.deleteBank("default");
// after
if (name === "default") continue; // or:
banks.deleteBank(name, /* force */ true);
Defensive patterns

Strategy: validation

Validate before calling

if (name === "default" && !force) {
  throw new Error("Refusing to delete the default bank without force");
}

Type guard

null

Try / catch

try {
  banks.deleteBank(name, force);
} catch (err) {
  if (err instanceof ValueError && err.message.includes("'default'")) {
    console.warn("Skipping protected default bank");
  } else throw err;
}

Prevention

When it happens

Trigger: Calling `deleteBank("default")` with no second argument, or the CLI equivalent of deleting the default bank without a `--force` flag.

Common situations: Cleanup scripts that iterate all banks including `default`, users trying to reset their data by deleting the default bank, automated teardown that assumed every bank is deletable.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/3580ab37a235a07b. Report an issue: GitHub.