Hmbown/CodeWhale · error
failed to install new binary at
Error message
failed to install new binary at {}: {} What it means
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.
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.
Example fix
// before (write to read-only system dir) codewhale update # target /usr/local/bin/codewhale, EACCES // after (user-writable target) codewhale update --install-dir ~/.local/bin
Defensive patterns
Strategy: try-catch
Validate before calling
// Check writability of the install dir before starting an update
let dir = target.parent().unwrap();
let probe = dir.join(".codewhale-write-probe");
if std::fs::write(&probe, b"").is_err() {
eprintln!("{} not writable; rerun with elevated privileges or --install-dir", dir.display());
}
let _ = std::fs::remove_file(&probe); Try / catch
if let Err(err) = tmp.persist(&target) {
// updater already restored the backup
eprintln!("install failed: {}", err.error);
if cfg!(windows) && err.error.to_string().contains("Access is denied") {
eprintln!("target exe is locked (running instance or antivirus); close it and retry");
} else if err.error.kind() == std::io::ErrorKind::PermissionDenied {
eprintln!("rerun with elevated privileges or choose a writable --install-dir");
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
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
- staged update is not executable (mode ); refusing to replace
- already exists; pass --force to overwrite it
- Android loaded image
- approval log has no parent
- artifact name is not portable UTF-8
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/929331cac2399ac0.
Report an issue: GitHub.
Appendix: source
Thrown at crates/cli/src/update.rs:1921
#[cfg(windows)]
{
let backup = backup_path_for(target);
if target.exists() {
std::fs::rename(target, &backup).with_context(|| {
format!(
"failed to move current executable {} to {}",
target.display(),
backup.display()
)
})?;
}
if let Err(err) = tmp.persist(target) {
if backup.exists() {
let _ = std::fs::rename(&backup, target);
}
bail!(
"failed to install new binary at {}: {}",
target.display(),
err.error
);
}
let _ = std::fs::remove_file(&backup);
}
#[cfg(not(windows))]
{
tmp.persist(target)
.map_err(|err| err.error)
.with_context(|| format!("failed to rename temp file to {}", target.display()))?;
}
Ok(())
}View on GitHub (pinned to 73e0f67d83)