can1357/oh-my-pi · error · ValueError

Bank '${name}' already exists

Error message

Bank '${name}' already exists

What it means

`BankManager.createBank()` refuses to create a bank whose on-disk directory already exists under the banks data directory. Each bank gets its own directory plus SQLite database, so an existing directory means the bank is already initialized; creating again would clobber it.

Source

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

	readonly db_path: string;
	readonly dbSizeBytes: number;
	readonly db_size_bytes: number;
}

export class BankManager {
	readonly dataDir: string;
	readonly banksDir: string;

	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 })) {

View on GitHub (pinned to 9690622007)

Solutions

  1. Check existence first with `getBankStats(name)` or `listBanks()` and skip creation if it already exists.
  2. Use a different bank name.
  3. Delete the unwanted bank with `deleteBank(name, true)` before recreating (destructive).
  4. Catch the ValueError and treat the existing bank as the target.

Example fix

// before
const dbPath = banks.createBank("work");
// after
const stats = banks.getBankStats("work");
const dbPath = stats.exists ? banks.getBankDbPath("work") : banks.createBank("work");
Defensive patterns

Strategy: try-catch

Validate before calling

import { existsSync } from "node:fs";
const bankDir = join(dataDir, "banks", name);
const alreadyExists = existsSync(bankDir);

Type guard

null

Try / catch

try {
  dbPath = banks.createBank(name);
} catch (err) {
  if (err instanceof ValueError && err.message.includes("already exists")) {
    dbPath = banks.getBankDbPath(name); // reuse existing
  } else throw err;
}

Prevention

When it happens

Trigger: Calling `createBank(name)` (or the `bank create` CLI command) when `<dataDir>/banks/<name>/` already exists — i.e. the bank was created previously and not deleted.

Common situations: Re-running an init/setup script twice, choosing a name that collides with an existing bank, teammate-created bank in a shared data dir, idempotency attempt that assumed create was upsert-like.

Related errors


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