{"record":{"id":"86ccf4f76e6140bd","repo":"BigPizzaV3/CodexPlusPlus","slug":"backup-source-database-not-found","errorCode":null,"errorMessage":"Backup source database not found: {}","messagePattern":"Backup source database not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-data/src/storage.rs","lineNumber":1001,"sourceCode":"                insert_row(db, table, row)?;\n            }\n        }\n    }\n    Ok(())\n}\n\nfn backup_source_db(\n    backup: &Value,\n    fallback_db_path: &Path,\n    allowed_db_paths: &[PathBuf],\n) -> anyhow::Result<PathBuf> {\n    let source_db = backup[\"source_db\"]\n        .as_str()\n        .filter(|path| !path.trim().is_empty())\n        .map(PathBuf::from)\n        .unwrap_or_else(|| fallback_db_path.to_path_buf());\n    if !source_db.is_file() {\n        anyhow::bail!(\n            \"Backup source database not found: {}\",\n            source_db.to_string_lossy()\n        );\n    }\n    let source_db = fs::canonicalize(source_db)?;\n    let allowed = allowed_db_paths\n        .iter()\n        .filter_map(|path| fs::canonicalize(path).ok())\n        .any(|path| path == source_db);\n    if !allowed {\n        anyhow::bail!(\"Backup source database is not an allowed local storage path\");\n    }\n    Ok(source_db)\n}\n\nfn schema_kind(db: &Connection) -> anyhow::Result<Option<SchemaKind>> {\n    if has_table(db, \"sessions\")? && has_columns(db, \"sessions\", &[\"id\", \"title\"])? {\n        if has_table(db, \"messages\")? && !has_columns(db, \"messages\", &[\"session_id\"])? {","sourceCodeStart":983,"sourceCodeEnd":1019,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-data/src/storage.rs#L983-L1019","documentation":"backup_source_db reads the source_db path recorded in a backup JSON, falling back to fallback_db_path when absent/blank, and bails if the resolved path is not an existing file. restore_backups needs the original database present on disk to write restored rows back into.","triggerScenarios":"Calling restore_backups with a backup whose source_db field points to a deleted/moved database file, or when both source_db is empty and the fallback_db_path doesn't exist on disk.","commonSituations":"Restoring a backup after the user deleted or relocated the codex DB (e.g. reinstalled codex, moved CODEX_HOME, ran cleanup tools); backup made on another machine with paths that don't exist locally; typo'd db_path configuration.","solutions":["Recreate the target database (open codex once so it creates its DB) before restoring the backup.","Fix the backup JSON's source_db (or pass a correct fallback_db_path) to point at the existing database file.","Restore the DB from OS-level backup or copy it back if it was moved; verify with a path existence check before restore.","If restoring from another machine, remap source_db to the local codex home path first."],"exampleFix":"// before\nstorage.restore_backups(&backup)?; // backup.source_db = \"/old/home/state.db\" (deleted)\n// after\nlet mut backup = backup.clone();\nif !Path::new(backup[\"source_db\"].as_str().unwrap_or(\"\")).is_file() {\n    backup[\"source_db\"] = json!(codex_home.join(\"state\").join(\"threads.sqlite\")); // re-anchor to current home\n}\nstorage.restore_backups(&backup)?;","handlingStrategy":"validation","validationCode":"let source_db = backup[\"source_db\"].as_str().unwrap_or(\"\");\nlet resolved = if source_db.trim().is_empty() { &fallback_db_path } else { Path::new(source_db) };\nif !resolved.is_file() {\n    anyhow::bail!(\"cannot restore: source db {} is missing; open codex once to recreate it\", resolved.display());\n}","typeGuard":"fn backup_source_exists(backup: &Value, fallback: &Path) -> bool {\n    let p = backup[\"source_db\"].as_str().filter(|s| !s.trim().is_empty())\n        .map(PathBuf::from).unwrap_or_else(|| fallback.to_path_buf());\n    p.is_file()\n}","tryCatchPattern":"match storage.restore_backups(&backup) {\n    Ok(()) => println!(\"restored\"),\n    Err(e) if e.to_string().starts_with(\"Backup source database not found\") => {\n        eprintln!(\"{e}; recreate the codex db or fix source_db path first\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Check source_db existence with Path::is_file before initiating any restore","Keep backups and their DBs in sync: don't relocate/delete CODEX_HOME while backups are pending","Re-anchor source_db paths when moving backups across machines or homes","Open codex once before restoring so the DB file exists"],"tags":["file-not-found","sqlite","restore"],"backgroundTag":"file-not-found","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}