{"id":"3ca1799f6f60d0f1","repo":"rust-lang/rust","slug":"failed-to-spawn-rustdoc","errorCode":null,"errorMessage":"Failed to spawn rustdoc: {}","messagePattern":"Failed to spawn rustdoc: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_codegen_cranelift/scripts/rustdoc-clif.rs","lineNumber":54,"sourceCode":"        args.push(OsString::from(sysroot.to_str().unwrap()));\n    }\n    if passed_args.is_empty() {\n        // Don't pass any arguments when the user didn't pass any arguments\n        // either to ensure the help message is shown.\n        args.clear();\n    }\n    args.extend(passed_args);\n\n    let rustdoc = if let Some(rustdoc) = option_env!(\"RUSTDOC\") {\n        rustdoc\n    } else {\n        // Ensure that the right toolchain is used\n        env::set_var(\"RUSTUP_TOOLCHAIN\", option_env!(\"TOOLCHAIN_NAME\").expect(\"TOOLCHAIN_NAME\"));\n        \"rustdoc\"\n    };\n\n    #[cfg(unix)]\n    panic!(\"Failed to spawn rustdoc: {}\", Command::new(rustdoc).args(args).exec());\n\n    #[cfg(not(unix))]\n    std::process::exit(\n        Command::new(rustdoc).args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1),\n    );\n}\n","sourceCodeStart":36,"sourceCodeEnd":61,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_cranelift/scripts/rustdoc-clif.rs#L36-L61","documentation":"Panics in the rustdoc-clif launcher shim when Command::exec() cannot replace the process with rustdoc. Identical shape to rustc-clif (error 63) but for the documentation driver; rustdoc-clif injects the cranelift backend and sysroot and then execs rustdoc.","triggerScenarios":"Reached at the tail of rustdoc-clif.rs (unix path) when exec of the assembled rustdoc Command fails. Only the exec syscall failure panics; rustdoc's own errors propagate via its exit code.","commonSituations":"rustdoc missing from the toolchain or RUSTDOC env var pointing at a bad path; rustup toolchain named by TOOLCHAIN_NAME not installed; running `cargo doc` via cargo-clif in a container where the docs component (`rust-docs` / `rust-src`) was omitted; relocation of the binary so the computed sysroot is wrong.","solutions":["Run `rustup toolchain list` and `rustup component add rust-docs --toolchain <toolchain>` for the expected toolchain.","Run `which rustdoc` / `$RUSTDOC --version` to confirm the binary is executable.","Invoke via `rustup run <toolchain> rustdoc-clif` so the component paths resolve.","Re-run `./y.rs prepare` to repair the toolchain install."],"exampleFix":"// before\n#[cfg(unix)]\npanic!(\"Failed to spawn rustdoc: {}\", Command::new(rustdoc).args(args).exec());\n// after\n#[cfg(unix)]\n{\n    eprintln!(\"rustdoc-clif: exec rustdoc={:?} sysroot={:?}\", rustdoc, sysroot);\n    panic!(\"Failed to spawn rustdoc: {}\", Command::new(rustdoc).args(args).exec());\n}","handlingStrategy":"validation","validationCode":"fn ensure_tool(name: &str) -> Result<(), String> {\n    if which::which(name).is_err() {\n        return Err(format!(\"{} not found on PATH; run `rustup component add rust-docs` or install rustdoc\", name));\n    }\n    Ok(())\n}\n// call ensure_tool(\"rustdoc\") before invoking rustdoc-clif","typeGuard":"fn rustdoc_available() -> bool {\n    std::process::Command::new(\"rustdoc\").arg(\"--version\").status().is_ok()\n}","tryCatchPattern":"use std::panic;\nif panic::catch_unwind(|| Command::new(\"rustdoc\").args(args).status()).is_err() {\n    eprintln!(\"rustdoc spawn failed; install rust-docs / fix PATH\"); std::process::exit(1);\n}","preventionTips":["Check `rustdoc --version` exists; it ships with rustc but can be omitted in minimal installs.","Ensure the same toolchain that provides rustc also provides rustdoc on PATH.","Avoid invoking rustdoc-clif from environments where the docs component is not installed.","Validate PATH is intact (e.g. login shells, CI images) before doc builds."],"tags":["cg-clif","launcher","process-spawn","unix","rustup","rustdoc"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}