gitbutlerapp/gitbutler · error

Cannot import TOML into DB: TOML does not exist or is…

Error message

Cannot import TOML into DB: TOML does not exist or is invalid

What it means

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.

Solutions

  1. Verify the TOML file exists and parses (e.g. with a TOML validator) before importing
  2. Re-restore the oplog/TOML from a good backup
  3. Check the path points to the correct snapshot file

Example fix

// before: import without checking
import_toml_into_db(Path::new("state.toml"))?;
// after: check readability first
if !path.exists() { restore_backup()?; }
import_toml_into_db(path)?;
Defensive patterns

Strategy: validation

Validate before calling

// before import
if !path.exists() {
    return Err(anyhow!("snapshot {} missing", path.display()));
}
let text = std::fs::read_to_string(path)?;
toml::from_str::<toml::Value>(&text)?; // parse check

Try / catch

// Rust
match import_toml_into_db(path) {
    Err(e) if e.to_string().contains("does not exist or is invalid") => {
        restore_from_backup()?;
        import_toml_into_db(path)?;
    }
    other => other,
}

Prevention

When it happens

Trigger: 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).

Common situations: Restoring from an oplog backup whose TOML was truncated or corrupted, wrong path passed after a restore, partially-written snapshot file.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/2dfcf8c99c3af8e1. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-meta/src/legacy/storage.rs:93

    }
    let mut snapshot = legacy_to_snapshot(vb, into_db_toml_file_info(db_state))?;
    let info = write_toml(path, vb)?;
    info.update_last_seen_metadata_on(&mut snapshot.state);
    persist_snapshot(&mut tx, snapshot)?;
    tx.commit()?;
    // The single choke point for metadata writes, so touching the sentinel here surfaces
    // out-of-process writes. Read-only syncs don't route through here.
    but_project_handle::write_refresh_sentinel(path);
    Ok(())
}

/// Import TOML into DB if TOML is valid, overwriting existing data forcefully.
///
/// This is meant for oplog restore and similar flows where TOML was restored externally.
pub fn import_toml_into_db(path: &Path) -> anyhow::Result<()> {
    let info = read_toml_info(path)?;
    let TomlInfo::Parsed(parsed) = info else {
        bail!("Cannot import TOML into DB: TOML does not exist or is invalid");
    };

    let mut db = db_handle_from_toml_path(path)?;
    let mut tx = db.immediate_transaction()?;
    let mut state = snapshot_state(path, &tx)?.unwrap_or_default().state;
    state.initialized = true;
    parsed.update_last_seen_metadata_on(&mut state);
    let snapshot = legacy_to_snapshot(&parsed.data, into_db_toml_file_info(state))?;
    persist_snapshot(&mut tx, snapshot)?;
    tx.commit()?;
    Ok(())
}

fn ensure_vb_storage_in_sync(
    path: &Path,
    tx: &mut but_db::Transaction<'_>,
) -> anyhow::Result<VirtualBranches> {
    let snapshot = snapshot_state(path, tx)?.unwrap_or_default();

View on GitHub (pinned to 58e5313667)