{"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":"anyhow::Error","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/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/but-meta/src/legacy/storage.rs#L75-L111","documentation":"`import_toml_into_db` force-imports an externally restored legacy metadata TOML into the SQLite store (oplog restore and similar flows). It first classifies the file with `read_toml_info`; anything other than `TomlInfo::Parsed` — missing file, unreadable file, or TOML that fails to parse — aborts before the database is touched.","triggerScenarios":"Calling `import_toml_into_db(path)` where the path does not point at a valid legacy metadata TOML file: file absent, empty, truncated, or syntactically invalid TOML.","commonSituations":"Oplog/backup restores where the TOML was never actually written back or landed at the wrong path; interrupted restores leaving truncated files; hand-edited metadata with syntax errors.","solutions":["Verify the TOML file exists at the expected path and parses before importing","Re-run the restore step that is supposed to produce the TOML, then retry the import","If the file was hand-edited, fix the TOML syntax or restore the original backup"],"exampleFix":"// before\nimport_toml_into_db(&path)?;\n\n// after: validate the payload parses as TOML first\nlet raw = std::fs::read_to_string(&path)?;\ntoml::from_str::<toml::Value>(&raw)?; // fails fast with a parse error\nimport_toml_into_db(&path)?;","handlingStrategy":"validation","validationCode":"// Rust: verify the restored TOML exists and parses before import\nlet raw = std::fs::read_to_string(&path)\n    .with_context(|| format!(\"metadata TOML missing at {}\", path.display()))?;\ntoml::from_str::<toml::Value>(&raw)?; // fails fast with a parse error\nimport_toml_into_db(&path)?;","typeGuard":null,"tryCatchPattern":"Catch the bail from import_toml_into_db and surface 'restore the metadata file first' — do not retry with the same broken payload.","preventionTips":["Validate backup/restore payloads right after they are written, before import","Treat a missing or unparseable TOML after a restore step as a restore failure, not an import failure"],"tags":["toml","import","restore","metadata","gitbutler"],"backgroundTag":"invalid-config-file","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}