can1357/oh-my-pi · error · ValueError

Bank name cannot be empty

Error message

Bank name cannot be empty

What it means

`validateName()` rejects an empty bank name string. Bank names become directory names, so an empty string would resolve to an invalid/ambiguous path.

Source

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

	}
	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`);
		for (let i = 0; i < name.length; i++) {
			const code = name.charCodeAt(i);
			const ok =
				(code >= 48 && code <= 57) ||
				(code >= 65 && code <= 90) ||
				(code >= 97 && code <= 122) ||
				code === 45 ||
				code === 95;
			if (!ok) throw new ValueError(`Invalid bank name '${name}'. Use alphanumeric, hyphens, underscores only.`);
		}
	}
}

let defaultBank = "default";

export function createBank(name: string, dataDir?: string): string {

View on GitHub (pinned to 9690622007)

Solutions

  1. Pass a non-empty name; default to `"default"` when the caller provides nothing: `name || "default"`.
  2. Trim and validate CLI/env input before calling the API.
  3. If the intent was the default bank, either pass `"default"` or use the API overload that omits the bank.
  4. In scripts, use `"${BANK:-default}"`.

Example fix

// before
banks.createBank(opts.bank);
// after
banks.createBank(opts.bank || "default");
Defensive patterns

Strategy: validation

Validate before calling

const bank = (process.env.MNEMOPI_BANK || "default").trim() || "default";
if (bank.length === 0) throw new Error("Bank name required");

Type guard

null

Try / catch

try {
  banks.createBank(name);
} catch (err) {
  if (err instanceof ValueError && err.message.includes("empty")) {
    name = "default";
    banks.createBank(name);
  } else throw err;
}

Prevention

When it happens

Trigger: Calling `createBank("")`, `deleteBank("")`, `renameBank(x, "")` (newName is validated), or `getBankDbPath("")` — the latter throws because only "default" or non-empty names take the per-bank path.

Common situations: Shell variables that expand to empty (`--bank "$BANK"` with unset BANK), config files with a blank bank field, argv parsing producing `""` for a missing value.

Related errors


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