{"record":{"id":"2dfcf8c99c3af8e1","repo":"gitbutlerapp/gitbutler","slug":"cannot-import-toml-into-db-toml-does-not-exist-or","errorCode":null,"errorMessage":"Cannot import TOML into DB: TOML does not exist or is invalid","messagePattern":"Cannot import TOML into DB: TOML does not exist or is invalid","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-meta/src/legacy/storage.rs","lineNumber":93,"sourceCode":"    }\n    let mut snapshot = legacy_to_snapshot(vb, into_db_toml_file_info(db_state))?;\n    let info = write_toml(path, vb)?;\n    info.update_last_seen_metadata_on(&mut snapshot.state);\n    persist_snapshot(&mut tx, snapshot)?;\n    tx.commit()?;\n    // The single choke point for metadata writes, so touching the sentinel here surfaces\n    // out-of-process writes. Read-only syncs don't route through here.\n    but_project_handle::write_refresh_sentinel(path);\n    Ok(())\n}\n\n/// Import TOML into DB if TOML is valid, overwriting existing data forcefully.\n///\n/// This is meant for oplog restore and similar flows where TOML was restored externally.\npub fn import_toml_into_db(path: &Path) -> anyhow::Result<()> {\n    let info = read_toml_info(path)?;\n    let TomlInfo::Parsed(parsed) = info else {\n        bail!(\"Cannot import TOML into DB: TOML does not exist or is invalid\");\n    };\n\n    let mut db = db_handle_from_toml_path(path)?;\n    let mut tx = db.immediate_transaction()?;\n    let mut state = snapshot_state(path, &tx)?.unwrap_or_default().state;\n    state.initialized = true;\n    parsed.update_last_seen_metadata_on(&mut state);\n    let snapshot = legacy_to_snapshot(&parsed.data, into_db_toml_file_info(state))?;\n    persist_snapshot(&mut tx, snapshot)?;\n    tx.commit()?;\n    Ok(())\n}\n\nfn ensure_vb_storage_in_sync(\n    path: &Path,\n    tx: &mut but_db::Transaction<'_>,\n) -> anyhow::Result<VirtualBranches> {\n    let snapshot = snapshot_state(path, tx)?.unwrap_or_default();","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-meta/src/legacy/storage.rs#L75-L111","documentation":"import_toml_into_db refuses to import when the TOML file at the given path cannot be read as a parsed snapshot (read_toml_info did not return TomlInfo::Parsed). It is used for oplog-restore flows, so it fails fast rather than importing corrupt or missing data into the DB.","triggerScenarios":"Calling import_toml_into_db(path) where the file does not exist, is unreadable, or failed TOML parsing (read_toml_info returned a non-Parsed variant).","commonSituations":"Restoring from an oplog backup whose TOML was truncated or corrupted, wrong path passed after a restore, partially-written snapshot file.","solutions":["Verify the TOML file exists and parses (e.g. with a TOML validator) before importing","Re-restore the oplog/TOML from a good backup","Check the path points to the correct snapshot file"],"exampleFix":"// before: import without checking\nimport_toml_into_db(Path::new(\"state.toml\"))?;\n// after: check readability first\nif !path.exists() { restore_backup()?; }\nimport_toml_into_db(path)?;","handlingStrategy":"validation","validationCode":"// before import\nif !path.exists() {\n    return Err(anyhow!(\"snapshot {} missing\", path.display()));\n}\nlet text = std::fs::read_to_string(path)?;\ntoml::from_str::<toml::Value>(&text)?; // parse check","typeGuard":null,"tryCatchPattern":"// Rust\nmatch import_toml_into_db(path) {\n    Err(e) if e.to_string().contains(\"does not exist or is invalid\") => {\n        restore_from_backup()?;\n        import_toml_into_db(path)?;\n    }\n    other => other,\n}","preventionTips":["Verify snapshot integrity (parse TOML) after every restore","Keep verified backups before oplog restore operations","Check the path before importing"],"tags":["toml","file","import","validation"],"backgroundTag":"file-not-found","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}