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
- Exclude `default` from rename operations (filter it out of lists).
- Create a new bank with the desired name and copy annotations into it instead of renaming.
- If the goal is changing which bank is active, change the selected bank rather than renaming `default`.
- 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
- Exclude "default" from any rename-all iteration.
- Never let user input select "default" as a rename source.
- Offer 'create new + copy' as the supported alternative.
- Log skips so silent no-ops are visible.
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
- Cannot delete 'default' bank without force=True
- Bank '${oldName}' does not exist
- Bank '${newName}' already exists
- rename target already exists: ${formatPathRelativeToCwd(newP
- Bank '${name}' already exists
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/4d90fe8192fdcd53.
Report an issue: GitHub.