{"record":{"id":"f1a771bebf85d0b9","repo":"cross-rs/cross","slug":"failed-to-get-rustup-version","errorCode":null,"errorMessage":"failed to get rustup version","messagePattern":"failed to get rustup version","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/rustup.rs","lineNumber":177,"sourceCode":"        installed,\n        not_installed,\n    })\n}\n\nfn version(msg_info: &mut MessageInfo) -> Result<Version> {\n    let out = rustup_command(msg_info, false)\n        .arg(\"--version\")\n        .run_and_get_stdout(msg_info)?;\n\n    match out\n        .lines()\n        .next()\n        .and_then(|line| line.split_whitespace().nth(1))\n    {\n        Some(version) => {\n            semver::Version::parse(version).wrap_err_with(|| \"failed to parse rustup version\")\n        }\n        None => eyre::bail!(\"failed to get rustup version\"),\n    }\n}\n\npub fn install_toolchain(toolchain: &QualifiedToolchain, msg_info: &mut MessageInfo) -> Result<()> {\n    let mut command = rustup_command(msg_info, false);\n    let toolchain = toolchain.to_string();\n    command.args([\"toolchain\", \"add\", &toolchain, \"--profile\", \"minimal\"]);\n    if version(msg_info)? >= semver::Version::new(1, 25, 0) {\n        command.arg(\"--force-non-host\");\n    }\n    command\n        .run(msg_info, false)\n        .wrap_err_with(|| format!(\"couldn't install toolchain `{toolchain}`\"))\n}\n\npub fn install(\n    target: &Target,\n    toolchain: &QualifiedToolchain,","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/cross-rs/cross/blob/8c1a8aa4b661711f4b7b6ac07c2e8929ce2f7d27/src/rustup.rs#L159-L195","documentation":"`version()` runs `rustup --version`, parses the first output line, and expects a semver token as the second whitespace-separated field. If the line is missing or has no version token, it bails with `failed to get rustup version`. This check exists to verify rustup is usable before operations like installing toolchains.","triggerScenarios":"`rustup --version` output contains no second field — e.g. rustup missing/aborting with only an error line, a wrapper script emitting custom text, or stderr/stdout capture returning empty output.","commonSituations":"rustup not installed or not on PATH (only an error line captured); extremely old or patched rustup builds with different `--version` output; broken rustup install where the binary exists but fails at startup (missing libgcc, corrupted toolchain); running inside images that shim rustup.","solutions":["Install/update rustup: `rustup --version` manually must print e.g. `rustup 1.26.0 (...)`; if not, reinstall via rustup.rs.","Ensure `rustup` is on PATH for the process (check PATH in CI/container environments).","Update rustup (`rustup self update`) if the version line format differs from expectations.","If rustup is present but crashing, repair the installation (`rustup toolchain install stable` or reinstall) — the failure usually precedes version parsing."],"exampleFix":"// before\nlet v = rustup::version(msg_info)?; // bails if no version token\n// after\nlet v = match rustup::version(msg_info) {\n    Ok(v) => v,\n    Err(e) => anyhow::bail!(\"rustup is missing or broken ({}). Install from https://rustup.rs\", e),\n};","handlingStrategy":"try-catch","validationCode":"fn rustup_ok() -> bool {\n    std::process::Command::new(\"rustup\").arg(\"--version\")\n        .output().map(|o| o.status.success() && !o.stdout.is_empty()).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match rustup::version(msg_info) {\n    Ok(v) => v,\n    Err(e) => return Err(anyhow!(\"rustup missing or broken: {e}; install via https://rustup.rs\")),\n}","preventionTips":["Verify `rustup --version` prints a version line in the exact environment (CI image, container) before running tools.","Keep rustup on PATH for the user/process running the command.","Run `rustup self update` when version output formats drift."],"tags":["rustup","cli","version","subprocess"],"backgroundTag":"command-not-found","analyzedSha":"8c1a8aa4b661711f4b7b6ac07c2e8929ce2f7d27","analyzedAt":"2026-09-13T15:10:43.988Z","contentChangedAt":"2026-09-13T15:10:43.988Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}