{"record":{"id":"7756ad7f85d4ef12","repo":"tobi/qmd","slug":"collection-collectionname-not-found","errorCode":null,"errorMessage":"Collection '${collectionName}' not found","messagePattern":"Collection '(.+?)' not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/store.ts","lineNumber":3667,"sourceCode":"  // Rename in store_collections\n  renameStoreCollection(db, oldName, newName);\n}\n\n// =============================================================================\n// Context Management Operations\n// =============================================================================\n\n/**\n * Insert or update a context for a specific collection and path prefix.\n *\n * `store_collections` is keyed by name (`TEXT PRIMARY KEY`), not an integer id.\n * #754 retargeted this query from the dropped `collections` table but left\n * `WHERE id = ?`, which throws `no such column: id`.\n */\nexport function insertContext(db: Database, collectionName: string, pathPrefix: string, context: string): void {\n  const coll = db.prepare(`SELECT name FROM store_collections WHERE name = ?`).get(collectionName) as { name: string } | null;\n  if (!coll) {\n    throw new Error(`Collection '${collectionName}' not found`);\n  }\n\n  updateStoreContext(db, coll.name, pathPrefix, context);\n}\n\n/**\n * Delete a context for a specific collection and path prefix.\n * Returns the number of contexts deleted.\n */\nexport function deleteContext(db: Database, collectionName: string, pathPrefix: string): number {\n  // Remove context from store_collections\n  const success = removeStoreContext(db, collectionName, pathPrefix);\n  return success ? 1 : 0;\n}\n\n/**\n * Delete all global contexts (contexts with empty path_prefix).\n * Returns the number of contexts deleted.","sourceCodeStart":3649,"sourceCodeEnd":3685,"githubUrl":"https://github.com/tobi/qmd/blob/dbfd0b4736aeaf761d1a16ca8e424f071df8feb9/src/store.ts#L3649-L3685","documentation":"insertContext() looks up the collection by name in store_collections before writing context; if no row matches the given name it throws rather than inserting context for a nonexistent collection (which would be silently lost).","triggerScenarios":"Calling insertContext(db, name, prefix, ctx) with a collection name that was never added (or was removed/renamed) — e.g. `qmd context add` before `qmd collection add`.","commonSituations":"Typos in collection names; running context commands after a collection rename; tests using in-memory DBs that never registered the collection.","solutions":["Create the collection first (qmd collection add) then add context","Verify the name via `qmd collection list` / a SELECT before inserting","Use the exact current name after renames"],"exampleFix":"// before\ninsertContext(db, 'mynote', '/', 'desc'); // collection is 'mynotes'\n// after\nconst exists = db.prepare('SELECT 1 FROM store_collections WHERE name=?').get('mynote');\nif (!exists) throw new Error('create collection first');\ninsertContext(db, 'mynote', '/', 'desc');","handlingStrategy":"validation","validationCode":"const ok = db.prepare('SELECT 1 FROM store_collections WHERE name=?').get(name); if (ok) insertContext(db, name, prefix, ctx);","typeGuard":"const collectionExists = (db: Database, n: string) => db.prepare('SELECT 1 FROM store_collections WHERE name=?').get(n) != null;","tryCatchPattern":null,"preventionTips":["Add collections before contexts","Reuse exact names from `qmd collection list`","Re-run context setup after renames"],"tags":["collection","context","not-found"],"backgroundTag":"resource-not-found","analyzedSha":"dbfd0b4736aeaf761d1a16ca8e424f071df8feb9","analyzedAt":"2026-08-28T18:07:46.628Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}