{"record":{"id":"4e97091f82294c77","repo":"rust-lang/rust-analyzer","slug":"failed-stderr","errorCode":null,"errorMessage":"{:?} failed, {}\nstderr:\n{}","messagePattern":"(.+?) failed, (.+?)\nstderr:\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/project-model/src/lib.rs","lineNumber":218,"sourceCode":"            ProjectManifest::ProjectJson(it)\n            | ProjectManifest::CargoToml(it)\n            | ProjectManifest::CargoScript(it) => it,\n        }\n    }\n}\n\nimpl fmt::Display for ProjectManifest {\n    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n        fmt::Display::fmt(self.manifest_path(), f)\n    }\n}\n\nfn utf8_stdout(cmd: &mut Command) -> anyhow::Result<String> {\n    let output = cmd.output().with_context(|| format!(\"{cmd:?} failed\"))?;\n    if !output.status.success() {\n        match String::from_utf8(output.stderr) {\n            Ok(stderr) if !stderr.is_empty() => {\n                bail!(\"{:?} failed, {}\\nstderr:\\n{}\", cmd, output.status, stderr)\n            }\n            _ => bail!(\"{:?} failed, {}\", cmd, output.status),\n        }\n    }\n    let stdout = String::from_utf8(output.stdout)?;\n    Ok(stdout.trim().to_owned())\n}\n\n#[derive(Clone, Debug, Default, PartialEq, Eq)]\npub enum InvocationStrategy {\n    Once,\n    #[default]\n    PerWorkspace,\n}\n\n/// A set of cfg-overrides per crate.\n#[derive(Default, Debug, Clone, Eq, PartialEq)]\npub struct CfgOverrides {","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/rust-lang/rust-analyzer/blob/e8f7e90aa3e7b26aa9a000200f606c1078da99ec/crates/project-model/src/lib.rs#L200-L236","documentation":"utf8_stdout runs a command (e.g. `rustc --print sysroot`, `cargo ...`) and requires exit success. When the command exits non-zero AND its stderr is non-empty UTF-8, it bails with this message embedding the command, exit status, and stderr. It surfaces toolchain command failures (missing component, bad toolchain, network errors from rustup) with diagnostics for debugging.","triggerScenarios":"Any utf8_stdout invocation whose command fails: `discover_sysroot_dir` running `rustc --print sysroot`, `rustc_print_cfg`, `rustc_crates`, `discover_rust_lib_src_dir_or_add_component` (rustup component add), or cargo metadata-style commands — with a non-zero exit and stderr output.","commonSituations":"Missing or broken rustup/rustc installation; nonexistent toolchain name; rustup failing to download a component (offline/no network); RUSTUP_TOOLCHAIN pointing at an uninstalled toolchain; disk full.","solutions":["Read the embedded stderr in the message — it names the underlying cause (missing toolchain, download failure, bad flag).","Run `rustup toolchain list` and install/repair the toolchain referenced by the failed command.","If a component is missing, run `rustup component add rust-src` (or the component named in stderr).","Check network/proxy settings if rustup downloads fail; verify `rustc --version` works manually."],"exampleFix":"// before (failing env)\nRUSTUP_TOOLCHAIN=nightly-9999 rust-analyzer\n// after\nrustup toolchain install nightly\nrustup component add rust-src --toolchain nightly\nRUSTUP_TOOLCHAIN=nightly rust-analyzer","handlingStrategy":"try-catch","validationCode":"// pre-flight: verify the toolchain works before driving discovery\nlet ok = Command::new(\"rustc\")\n    .args([\"--version\"])\n    .output()\n    .map(|o| o.status.success())\n    .unwrap_or(false);\nif !ok {\n    // fix PATH / run `rustup toolchain install` before proceeding\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"failed\") && e.to_string().contains(\"stderr:\") => {\n        let stderr = /* extract stderr section from message */;\n        if stderr.contains(\"can't find crate\") || stderr.contains(\"toolchain\") {\n            // run `rustup toolchain install <name>` / `rustup component add rust-src`\n        }\n    }\n    _ => {}\n}","preventionTips":["Ensure rustc/cargo/rustup are installed and on PATH.","Install required components (`rust-src`) for the active toolchain.","Pin a valid RUSTUP_TOOLCHAIN; verify with `rustup toolchain list`.","Check network access for rustup component downloads."],"tags":["toolchain","rustup","rustc","process-failure"],"backgroundTag":"toolchain-command-failed","analyzedSha":"e8f7e90aa3e7b26aa9a000200f606c1078da99ec","analyzedAt":"2026-09-03T21:08:06.959Z","contentChangedAt":"2026-09-03T21:08:06.959Z","schemaVersion":2},"datasetVersion":"2026-09-11T07:07:21.782Z"}