gitbutlerapp/gitbutler · critical
Failed to rename to - application may fail to startup
Error message
Failed to rename {} to {} - application may fail to startup: {err} What it means
assure_database_valid recovers from an invalid projects database by renaming the bad DB file to a backup path. If the filesystem rename fails, it bails because continuing would leave the app with a broken database and a failed startup.
Solutions
- Close all GitButler instances and file lockers (sync clients, antivirus) that hold the DB open, then retry.
- Check permissions and free disk space on the directory containing the DB.
- Manually rename/move the corrupt DB file aside yourself, then restart the app so it recreates a fresh database.
- Restore the DB from backup if the data matters.
Example fix
// before (rename fails, file locked) $ but app start // after $ pkill gitbutler; dropbox pause $ mv projects.db projects.db.corrupt $ but app start # database recreated fresh
Defensive patterns
Strategy: try-catch
Validate before calling
let dir = db_path.parent().unwrap();
let probe = dir.join(".write-test");
let writable = std::fs::write(&probe, b"x").is_ok() && std::fs::remove_file(&probe).is_ok();
let free_space_ok = fs4::available_space(dir)? > db_path.metadata()?.len() * 2; Try / catch
match result {
Err(e) if e.to_string().contains("Failed to rename") => {
// close other instances, then manually move the DB aside and restart
}
other => other,
} Prevention
- Run only one app instance against the same database.
- Keep the DB out of sync-client/monitored folders.
- Monitor disk space and directory permissions.
- Back up the projects DB regularly.
When it happens
Trigger: Calling assure_database_valid (via set_project_active) when the DB file fails validation AND std::fs::rename(db_path, backup_path) errors — permission denied, file locked by another process, cross-filesystem rename, or read-only media.
Common situations: SQLite file locked by a running/previous GitButler instance; disk full; permission changes after an OS update; DB on a synced/mounted folder where renames fail.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- There were already backup project files - giving up
- broker already configured
- Could not open projects file at
- Database file at ' has corrupted copies - giving up…
- Failed to build tauri app
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/2859bcd5bfa9619e.
Report an issue: GitHub.
Appendix: source
Thrown at crates/gitbutler-tauri/src/projects.rs:143
this app was used to open the project. '{}' is incompatible",
db_path.display()
)
})
.context(but_error::Code::ProjectDatabaseIncompatible);
}
let db_filename = db_path.file_name().unwrap();
let max_attempts = 255;
for round in 1..max_attempts {
let backup_path = data_dir.join(format!(
"{db_name}.maybe-broken-{round:02}",
db_name = Path::new(db_filename).display()
));
if backup_path.is_file() {
continue;
}
if let Err(err) = std::fs::rename(&db_path, &backup_path) {
bail!(
"Failed to rename {} to {} - application may fail to startup: {err}",
db_path.display(),
backup_path.display()
);
}
return Ok(Some(format!(
"Could not open db file at '{}'.\nIt was moved to {} for recovery. \n\nError was: {err}",
db_path.display(),
backup_path.display()
)));
}
bail!(
"Database file at '{db_path} has {max_attempts} corrupted copies - giving up, application probably won't work",
db_path = db_path.display()
);
}
Ok(None)View on GitHub (pinned to 58e5313667)