{"record":{"id":"929331cac2399ac0","repo":"Hmbown/CodeWhale","slug":"failed-to-install-new-binary-at","errorCode":null,"errorMessage":"failed to install new binary at {}: {}","messagePattern":"failed to install new binary at (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/update.rs","lineNumber":1921,"sourceCode":"\n    #[cfg(windows)]\n    {\n        let backup = backup_path_for(target);\n        if target.exists() {\n            std::fs::rename(target, &backup).with_context(|| {\n                format!(\n                    \"failed to move current executable {} to {}\",\n                    target.display(),\n                    backup.display()\n                )\n            })?;\n        }\n\n        if let Err(err) = tmp.persist(target) {\n            if backup.exists() {\n                let _ = std::fs::rename(&backup, target);\n            }\n            bail!(\n                \"failed to install new binary at {}: {}\",\n                target.display(),\n                err.error\n            );\n        }\n\n        let _ = std::fs::remove_file(&backup);\n    }\n\n    #[cfg(not(windows))]\n    {\n        tmp.persist(target)\n            .map_err(|err| err.error)\n            .with_context(|| format!(\"failed to rename temp file to {}\", target.display()))?;\n    }\n\n    Ok(())\n}","sourceCodeStart":1903,"sourceCodeEnd":1939,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/cli/src/update.rs#L1903-L1939","documentation":"Thrown when the final atomic install of the updated binary fails. The updater uses tempfile::persist to move the staged file over the running binary; if the OS refuses (cross-filesystem move, target locked, permission denied), it restores the backup it made and reports the underlying error via err.error.","triggerScenarios":"Self-update calls tmp.persist(target) and gets an error, e.g. target binary is busy (Windows file lock), the temp dir and target are on different filesystems, or the user lacks write permission on the install directory.","commonSituations":"Windows: the CLI is running and the exe is locked by antivirus or another instance; Linux: no write permission to /usr/local/bin or the install prefix; temp dir on a different mount than the binary.","solutions":["Check the inner error in the message: for 'busy'/locked targets close other instances of the CLI (and AV scanners) and retry.","Install to a directory the user can write, or re-run the update with elevated privileges.","Ensure temp dir and install target share a filesystem so persist can rename in place.","Manually move the staged binary from the temp path shown in earlier output to the target location."],"exampleFix":"// before (write to read-only system dir)\ncodewhale update  # target /usr/local/bin/codewhale, EACCES\n// after (user-writable target)\ncodewhale update --install-dir ~/.local/bin","handlingStrategy":"try-catch","validationCode":"// Check writability of the install dir before starting an update\nlet dir = target.parent().unwrap();\nlet probe = dir.join(\".codewhale-write-probe\");\nif std::fs::write(&probe, b\"\").is_err() {\n    eprintln!(\"{} not writable; rerun with elevated privileges or --install-dir\", dir.display());\n}\nlet _ = std::fs::remove_file(&probe);","typeGuard":null,"tryCatchPattern":"if let Err(err) = tmp.persist(&target) {\n    // updater already restored the backup\n    eprintln!(\"install failed: {}\", err.error);\n    if cfg!(windows) && err.error.to_string().contains(\"Access is denied\") {\n        eprintln!(\"target exe is locked (running instance or antivirus); close it and retry\");\n    } else if err.error.kind() == std::io::ErrorKind::PermissionDenied {\n        eprintln!(\"rerun with elevated privileges or choose a writable --install-dir\");\n    }\n}","preventionTips":["Install into a user-writable prefix (~/.local/bin) to avoid permission issues.","On Windows, close all running CLI instances before updating.","Keep temp dir and install target on the same filesystem so rename/persist succeeds.","Exclude the install directory from antivirus scanning if it locks binaries."],"tags":["update","filesystem","install"],"backgroundTag":"file-write-failed","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}