can1357/oh-my-pi · error · ValueError

Cannot rename 'default' bank

Error message

Cannot rename 'default' bank

What it means

`renameBank()` outright refuses to rename the built-in `default` bank. The default bank is a fixed singleton bound to the root database path, not a directory under `banks/`, so renaming it has no valid representation on disk.

Source

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

		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));
	}
	getBankDbPath(name: string): string {
		if (name.length === 0 || name === "default") return join(this.dataDir, DB_FILENAME);
		this.validateName(name);
		return join(this.banksDir, name, DB_FILENAME);
	}
	renameBank(oldName: string, newName: string): string {
		if (oldName === "default") throw new ValueError("Cannot rename 'default' bank");
		this.validateName(newName);
		const oldDir = join(this.banksDir, oldName);
		const newDir = join(this.banksDir, newName);
		if (!existsSync(oldDir)) throw new ValueError(`Bank '${oldName}' does not exist`);
		if (existsSync(newDir)) throw new ValueError(`Bank '${newName}' already exists`);
		renameSync(oldDir, newDir);
		return join(newDir, DB_FILENAME);
	}
	getBankStats(name: string): BankStats {
		const dbPath = this.getBankDbPath(name);
		const present = existsSync(dbPath);
		const size = present ? statSync(dbPath).size : 0;
		return { name, exists: present, db_path: dbPath, dbSizeBytes: size, db_size_bytes: size };
	}
	private validateName(name: string): void {
		if (name.length === 0) throw new ValueError("Bank name cannot be empty");
		if (name === "default") return;
		if (name.length > 64) throw new ValueError(`Bank name '${name}' exceeds 64 characters`);

View on GitHub (pinned to 9690622007)

Solutions

  1. Exclude `default` from rename operations (filter it out of lists).
  2. Create a new bank with the desired name and copy annotations into it instead of renaming.
  3. If the goal is changing which bank is active, change the selected bank rather than renaming `default`.
  4. Catch the ValueError and skip/log for rename-all scripts.

Example fix

// before
banks.renameBank(name, newName); // name may be "default"
// after
if (name !== "default") banks.renameBank(name, newName);
Defensive patterns

Strategy: validation

Validate before calling

if (oldName === "default") {
  throw new Error("The default bank cannot be renamed");
}

Type guard

null

Try / catch

try {
  banks.renameBank(oldName, newName);
} catch (err) {
  if (err instanceof ValueError && err.message === "Cannot rename 'default' bank") {
    console.warn("Skipping default bank rename");
  } else throw err;
}

Prevention

When it happens

Trigger: Calling `renameBank("default", anyNewName)` directly or via a CLI rename command where the source bank is `default`.

Common situations: Bulk-rename loops over `listBanks()` output that includes `default`, users wanting to rebrand their primary bank, scripts migrating bank layouts.

Related errors


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