{"record":{"id":"d0a1df5f2c60f91c","repo":"can1357/oh-my-pi","slug":"bank-name-cannot-be-empty","errorCode":null,"errorMessage":"Bank name cannot be empty","messagePattern":"Bank name cannot be empty","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/mnemopi/src/core/banks.ts","lineNumber":86,"sourceCode":"\t}\n\trenameBank(oldName: string, newName: string): string {\n\t\tif (oldName === \"default\") throw new ValueError(\"Cannot rename 'default' bank\");\n\t\tthis.validateName(newName);\n\t\tconst oldDir = join(this.banksDir, oldName);\n\t\tconst newDir = join(this.banksDir, newName);\n\t\tif (!existsSync(oldDir)) throw new ValueError(`Bank '${oldName}' does not exist`);\n\t\tif (existsSync(newDir)) throw new ValueError(`Bank '${newName}' already exists`);\n\t\trenameSync(oldDir, newDir);\n\t\treturn join(newDir, DB_FILENAME);\n\t}\n\tgetBankStats(name: string): BankStats {\n\t\tconst dbPath = this.getBankDbPath(name);\n\t\tconst present = existsSync(dbPath);\n\t\tconst size = present ? statSync(dbPath).size : 0;\n\t\treturn { name, exists: present, db_path: dbPath, dbSizeBytes: size, db_size_bytes: size };\n\t}\n\tprivate validateName(name: string): void {\n\t\tif (name.length === 0) throw new ValueError(\"Bank name cannot be empty\");\n\t\tif (name === \"default\") return;\n\t\tif (name.length > 64) throw new ValueError(`Bank name '${name}' exceeds 64 characters`);\n\t\tfor (let i = 0; i < name.length; i++) {\n\t\t\tconst code = name.charCodeAt(i);\n\t\t\tconst ok =\n\t\t\t\t(code >= 48 && code <= 57) ||\n\t\t\t\t(code >= 65 && code <= 90) ||\n\t\t\t\t(code >= 97 && code <= 122) ||\n\t\t\t\tcode === 45 ||\n\t\t\t\tcode === 95;\n\t\t\tif (!ok) throw new ValueError(`Invalid bank name '${name}'. Use alphanumeric, hyphens, underscores only.`);\n\t\t}\n\t}\n}\n\nlet defaultBank = \"default\";\n\nexport function createBank(name: string, dataDir?: string): string {","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/mnemopi/src/core/banks.ts#L68-L104","documentation":"`validateName()` rejects an empty bank name string. Bank names become directory names, so an empty string would resolve to an invalid/ambiguous path.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a non-empty name; default to `\"default\"` when the caller provides nothing: `name || \"default\"`.","Trim and validate CLI/env input before calling the API.","If the intent was the default bank, either pass `\"default\"` or use the API overload that omits the bank.","In scripts, use `\"${BANK:-default}\"`."],"exampleFix":"// before\nbanks.createBank(opts.bank);\n// after\nbanks.createBank(opts.bank || \"default\");","handlingStrategy":"validation","validationCode":"const bank = (process.env.MNEMOPI_BANK || \"default\").trim() || \"default\";\nif (bank.length === 0) throw new Error(\"Bank name required\");","typeGuard":"null","tryCatchPattern":"try {\n  banks.createBank(name);\n} catch (err) {\n  if (err instanceof ValueError && err.message.includes(\"empty\")) {\n    name = \"default\";\n    banks.createBank(name);\n  } else throw err;\n}","preventionTips":["Always default empty input to \"default\".","Trim CLI/env values before use.","Require --bank explicitly in scripts (`${BANK:?}` in bash).","Reject empty names at your app's input layer."],"tags":["bank","validation","empty-string"],"backgroundTag":"invalid-argument","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}