{"record":{"id":"d9009bc41080457c","repo":"rust-lang/rust","slug":"could-not-run-rustfmt-please-make-sure-it-is-in-y","errorCode":null,"errorMessage":"Could not run rustfmt, please make sure it is in your PATH.","messagePattern":"Could not run rustfmt, please make sure it is in your PATH\\.","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"src/tools/rustfmt/src/cargo-fmt/main.rs","lineNumber":262,"sourceCode":"}\n\nfn handle_command_status(status: Result<i32, io::Error>) -> i32 {\n    match status {\n        Err(e) => {\n            print_usage_to_stderr(&e.to_string());\n            FAILURE\n        }\n        Ok(status) => status,\n    }\n}\n\nfn get_rustfmt_info(args: &[String]) -> Result<i32, io::Error> {\n    let mut command = rustfmt_command()\n        .stdout(std::process::Stdio::inherit())\n        .args(args)\n        .spawn()\n        .map_err(|e| match e.kind() {\n            io::ErrorKind::NotFound => io::Error::new(\n                io::ErrorKind::Other,\n                \"Could not run rustfmt, please make sure it is in your PATH.\",\n            ),\n            _ => e,\n        })?;\n    let result = command.wait()?;\n    if result.success() {\n        Ok(SUCCESS)\n    } else {\n        Ok(result.code().unwrap_or(SUCCESS))\n    }\n}\n\nfn format_crate(\n    verbosity: Verbosity,\n    strategy: &CargoFmtStrategy,\n    rustfmt_args: Vec<String>,\n    manifest_path: Option<&Path>,","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/tools/rustfmt/src/cargo-fmt/main.rs#L244-L280","documentation":"Returned by cargo-fmt's get_rustfmt_info when spawning the rustfmt child process fails with ErrorKind::NotFound. cargo-fmt translates the raw NotFound into a friendlier message directing the user to install/PATH rustfmt. All other spawn errors propagate unchanged. This is the entry-point info-gathering spawn (e.g. --help/version passthrough).","triggerScenarios":"Running `cargo fmt` (which is cargo-fmt) when the rustfmt executable cannot be found on PATH - component not installed via rustup, custom toolchain missing rustfmt, or PATH not propagated to the shell. The .spawn() call returns NotFound and is mapped to this message.","commonSituations":"rustfmt/rustfmt-preview component not installed for the active toolchain; using a minimal/custom toolchain without rustfmt; running inside an IDE/clean environment with a stripped PATH; wrong toolchain selected by rustup.","solutions":["Install the component: `rustup component add rustfmt` (or rustfmt-preview on nightly).","Confirm the active toolchain has rustfmt: `rustup which rustfmt` / `rustfmt --version`.","Ensure the directory containing rustfmt is on PATH for the shell/IDE launching cargo-fmt.","If using a custom toolchain, build/install rustfmt into that toolchain's bin dir."],"exampleFix":"# before: cargo fmt -> Could not run rustfmt...\n\n# after\nrustup component add rustfmt\ncargo fmt","handlingStrategy":"validation","validationCode":"fn rustfmt_present() -> bool {\n    std::process::Command::new(\"rustfmt\").arg(\"--version\").output().is_ok()\n}\n// Before running cargo fmt: assert rustfmt_present().","typeGuard":null,"tryCatchPattern":"match get_rustfmt_info(args) {\n    Ok(code) => Ok(code),\n    Err(e) if e.to_string().contains(\"make sure it is in your PATH\") => {\n        // instruct: rustup component add rustfmt\n        Err(e)\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Install the rustfmt component for the active toolchain.","Verify `rustup which rustfmt` resolves before running cargo fmt.","Ensure the toolchain bin dir is on PATH for shells and IDEs."],"tags":["rustfmt","cargo-fmt","toolchain","path","rustup","io"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}