{"record":{"id":"218da0907e7a63c7","repo":"nikivdev/code","slug":"new-binary-validation-failed","errorCode":null,"errorMessage":"New binary validation failed","messagePattern":"New binary validation failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/upgrade.rs","lineNumber":476,"sourceCode":"    let source_assets = bundle_root.join(\"share\").join(\"flow\");\n    if !source_assets.is_dir() {\n        return Ok(());\n    }\n    let Some(dest_assets) = runtime_assets::installed_assets_root_for_exe(output_path) else {\n        return Ok(());\n    };\n    copy_dir_recursive(&source_assets, &dest_assets)\n}\n\n/// Validate the new binary by running --version.\nfn validate_binary(path: &Path) -> Result<String> {\n    let output = Command::new(path)\n        .arg(\"--version\")\n        .output()\n        .context(\"Failed to validate new binary\")?;\n\n    if !output.status.success() {\n        bail!(\"New binary validation failed\");\n    }\n\n    Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())\n}\n\n/// Replace the current executable with the new one.\nfn replace_executable(new_exe: &Path, current_exe: &Path) -> Result<()> {\n    #[cfg(unix)]\n    {\n        // On Unix, we can delete the running executable and replace it\n        fs::remove_file(current_exe).context(\"Failed to remove current executable\")?;\n        fs::copy(new_exe, current_exe).context(\"Failed to copy new executable\")?;\n\n        // Set executable permissions\n        use std::os::unix::fs::PermissionsExt;\n        let mut perms = fs::metadata(current_exe)?.permissions();\n        perms.set_mode(0o755);\n        fs::set_permissions(current_exe, perms)?;","sourceCodeStart":458,"sourceCodeEnd":494,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/upgrade.rs#L458-L494","documentation":"`validate_binary` (src/upgrade.rs:~470) smoke-tests the freshly downloaded binary by running `<path> --version` via `Command::new`. If the process cannot produce a successful exit status, the upgrade aborts with \"New binary validation failed\" to avoid replacing the working executable with a broken one.","triggerScenarios":"Running the extracted binary with `--version` returns a non-zero exit code: the artifact is for the wrong OS/architecture, is truncated/corrupt, lacks the exec bit or fails to load its dynamic libraries, or the new version's `--version` flag changed/panics.","commonSituations":"Downloading an x86_64 build on ARM (Apple Silicon / aarch64 servers); musl vs glibc mismatch causing loader failure; quarantine/Gatekeeper or missing +x permission; broken release CI shipped a bad binary.","solutions":["Run the extracted binary manually with `--version` to see the real error (exec format error, missing .so, etc.).","Confirm the downloaded asset matches your OS and architecture, then re-run the upgrade.","Check `file <binary>` — 'cannot execute binary file' means wrong arch or truncated download.","Re-download after the maintainers fix the release, or pin/downgrade to the previous working version.","Run `chmod +x <binary>` if the exec bit is missing and retry."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# smoke-test before replacing the installed binary\nfile \"$NEW_BIN\"                       # right arch? complete file?\nchmod +x \"$NEW_BIN\" && \"$NEW_BIN\" --version || echo \"new binary broken; keep current version\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Match the asset to your OS/arch (aarch64 vs x86_64, musl vs glibc).","Keep the previous binary until the new one passes `--version`.","Run the extracted binary manually to see loader errors before upgrading.","On macOS, clear quarantine: `xattr -d com.apple.quarantine <bin>`."],"tags":["binary-validation","architecture-mismatch","upgrade"],"backgroundTag":"binary-exec-validation-failed","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}