{"record":{"id":"3580ab37a235a07b","repo":"can1357/oh-my-pi","slug":"cannot-delete-default-bank-without-force-true","errorCode":null,"errorMessage":"Cannot delete 'default' bank without force=True","messagePattern":"Cannot delete 'default' bank without force=True","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"packages/mnemopi/src/core/banks.ts","lineNumber":45,"sourceCode":"\tconstructor(dataDir?: string) {\n\t\tthis.dataDir = dataDir ?? configuredDataDir();\n\t\tthis.banksDir = join(this.dataDir, \"banks\");\n\t\tmkdirSync(this.banksDir, { recursive: true });\n\t}\n\n\tcreateBank(name: string): string {\n\t\tthis.validateName(name);\n\t\tconst bankDir = join(this.banksDir, name);\n\t\tif (existsSync(bankDir)) throw new ValueError(`Bank '${name}' already exists`);\n\t\tmkdirSync(bankDir, { recursive: true });\n\t\tconst dbPath = join(bankDir, DB_FILENAME);\n\t\tconst db = openDatabase(dbPath);\n\t\tcloseQuietly(db);\n\t\treturn dbPath;\n\t}\n\tdeleteBank(name: string, force = false): boolean {\n\t\tthis.validateName(name);\n\t\tif (name === \"default\" && !force) throw new ValueError(\"Cannot delete 'default' bank without force=True\");\n\t\tconst bankDir = join(this.banksDir, name);\n\t\tif (!existsSync(bankDir)) return false;\n\t\trmSync(bankDir, { recursive: true, force: true });\n\t\treturn true;\n\t}\n\tlistBanks(): string[] {\n\t\tconst banks: string[] = [\"default\"];\n\t\tif (existsSync(this.banksDir)) {\n\t\t\tfor (const entry of readdirSync(this.banksDir, { withFileTypes: true })) {\n\t\t\t\tif (entry.isDirectory() && entry.name !== \"default\") banks.push(entry.name);\n\t\t\t}\n\t\t}\n\t\treturn banks.sort();\n\t}\n\tbankExists(name: string): boolean {\n\t\tif (name === \"default\") return true;\n\t\treturn existsSync(join(this.banksDir, name));\n\t}","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/mnemopi/src/core/banks.ts#L27-L63","documentation":"The built-in `default` bank is protected: `deleteBank()` refuses to remove it unless `force` is explicitly true. This prevents accidentally wiping the bank that all unqualified operations use.","triggerScenarios":"Calling `deleteBank(\"default\")` with no second argument, or the CLI equivalent of deleting the default bank without a `--force` flag.","commonSituations":"Cleanup scripts that iterate all banks including `default`, users trying to reset their data by deleting the default bank, automated teardown that assumed every bank is deletable.","solutions":["Pass `force = true` if you really intend to delete it: `deleteBank(\"default\", true)`.","Skip the default bank in cleanup loops (`if (name === \"default\") continue;`).","Instead of deleting, clear its contents via the annotations API if the goal is reset-without-removal.","Back up the bank directory before forcing deletion."],"exampleFix":"// before\nbanks.deleteBank(\"default\");\n// after\nif (name === \"default\") continue; // or:\nbanks.deleteBank(name, /* force */ true);","handlingStrategy":"validation","validationCode":"if (name === \"default\" && !force) {\n  throw new Error(\"Refusing to delete the default bank without force\");\n}","typeGuard":"null","tryCatchPattern":"try {\n  banks.deleteBank(name, force);\n} catch (err) {\n  if (err instanceof ValueError && err.message.includes(\"'default'\")) {\n    console.warn(\"Skipping protected default bank\");\n  } else throw err;\n}","preventionTips":["Filter out \"default\" in bulk-cleanup loops.","Require an explicit user opt-in before force-deleting default.","Snapshot/back up before any force delete.","Document that 'default' is protected in tooling docs."],"tags":["bank","default-bank","protected-resource","delete"],"backgroundTag":"protected-resource-delete","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}