rust-lang/rust-analyzer · error

{:?} failed, {} stderr: {}

Error message

{:?} failed, {}
stderr:
{}

What it means

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.

Source

Thrown at crates/project-model/src/lib.rs:218

            ProjectManifest::ProjectJson(it)
            | ProjectManifest::CargoToml(it)
            | ProjectManifest::CargoScript(it) => it,
        }
    }
}

impl fmt::Display for ProjectManifest {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        fmt::Display::fmt(self.manifest_path(), f)
    }
}

fn utf8_stdout(cmd: &mut Command) -> anyhow::Result<String> {
    let output = cmd.output().with_context(|| format!("{cmd:?} failed"))?;
    if !output.status.success() {
        match String::from_utf8(output.stderr) {
            Ok(stderr) if !stderr.is_empty() => {
                bail!("{:?} failed, {}\nstderr:\n{}", cmd, output.status, stderr)
            }
            _ => bail!("{:?} failed, {}", cmd, output.status),
        }
    }
    let stdout = String::from_utf8(output.stdout)?;
    Ok(stdout.trim().to_owned())
}

#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub enum InvocationStrategy {
    Once,
    #[default]
    PerWorkspace,
}

/// A set of cfg-overrides per crate.
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct CfgOverrides {

View on GitHub (pinned to e8f7e90aa3)

Solutions

  1. Read the embedded stderr in the message — it names the underlying cause (missing toolchain, download failure, bad flag).
  2. Run `rustup toolchain list` and install/repair the toolchain referenced by the failed command.
  3. If a component is missing, run `rustup component add rust-src` (or the component named in stderr).
  4. Check network/proxy settings if rustup downloads fail; verify `rustc --version` works manually.

Example fix

// before (failing env)
RUSTUP_TOOLCHAIN=nightly-9999 rust-analyzer
// after
rustup toolchain install nightly
rustup component add rust-src --toolchain nightly
RUSTUP_TOOLCHAIN=nightly rust-analyzer
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-flight: verify the toolchain works before driving discovery
let ok = Command::new("rustc")
    .args(["--version"])
    .output()
    .map(|o| o.status.success())
    .unwrap_or(false);
if !ok {
    // fix PATH / run `rustup toolchain install` before proceeding
}

Try / catch

match result {
    Err(e) if e.to_string().contains("failed") && e.to_string().contains("stderr:") => {
        let stderr = /* extract stderr section from message */;
        if stderr.contains("can't find crate") || stderr.contains("toolchain") {
            // run `rustup toolchain install <name>` / `rustup component add rust-src`
        }
    }
    _ => {}
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of rust-lang/rust-analyzer@e8f7e90aa3 (2026-09-03). Data as JSON: /api/errors/4e97091f82294c77. Report an issue: GitHub.