{"record":{"id":"2859bcd5bfa9619e","repo":"gitbutlerapp/gitbutler","slug":"failed-to-rename-to-application-may-fail-t","errorCode":null,"errorMessage":"Failed to rename {} to {} - application may fail to startup: {err}","messagePattern":"Failed to rename (.+?) to (.+?) - application may fail to startup: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/gitbutler-tauri/src/projects.rs","lineNumber":143,"sourceCode":"                         this app was used to open the project. '{}' is incompatible\",\n                        db_path.display()\n                    )\n                })\n                .context(but_error::Code::ProjectDatabaseIncompatible);\n        }\n        let db_filename = db_path.file_name().unwrap();\n        let max_attempts = 255;\n        for round in 1..max_attempts {\n            let backup_path = data_dir.join(format!(\n                \"{db_name}.maybe-broken-{round:02}\",\n                db_name = Path::new(db_filename).display()\n            ));\n            if backup_path.is_file() {\n                continue;\n            }\n\n            if let Err(err) = std::fs::rename(&db_path, &backup_path) {\n                bail!(\n                    \"Failed to rename {} to {} - application may fail to startup: {err}\",\n                    db_path.display(),\n                    backup_path.display()\n                );\n            }\n\n            return Ok(Some(format!(\n                \"Could not open db file at '{}'.\\nIt was moved to {} for recovery. \\n\\nError was: {err}\",\n                db_path.display(),\n                backup_path.display()\n            )));\n        }\n        bail!(\n            \"Database file at '{db_path} has {max_attempts} corrupted copies - giving up, application probably won't work\",\n            db_path = db_path.display()\n        );\n    }\n    Ok(None)","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/gitbutler-tauri/src/projects.rs#L125-L161","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (rename fails, file locked)\n$ but app start\n// after\n$ pkill gitbutler; dropbox pause\n$ mv projects.db projects.db.corrupt\n$ but app start  # database recreated fresh","handlingStrategy":"try-catch","validationCode":"let dir = db_path.parent().unwrap();\nlet probe = dir.join(\".write-test\");\nlet writable = std::fs::write(&probe, b\"x\").is_ok() && std::fs::remove_file(&probe).is_ok();\nlet free_space_ok = fs4::available_space(dir)? > db_path.metadata()?.len() * 2;","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"Failed to rename\") => {\n        // close other instances, then manually move the DB aside and restart\n    }\n    other => other,\n}","preventionTips":["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."],"tags":["database","sqlite","file-rename","startup","rust"],"backgroundTag":"file-write-failed","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"}