{"record":{"id":"e804c58616135725","repo":"rust-lang/rust","slug":"rustfmt-failed","errorCode":null,"errorMessage":"`rustfmt` failed","messagePattern":"`rustfmt` failed","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/tools/miri/miri-script/src/util.rs","lineNumber":296,"sourceCode":"            );\n            if first {\n                // Log an abbreviating command, and only once.\n                eprintln!(\"$ {cmd} ...\");\n                first = false;\n            }\n            // Add files.\n            for file in batch {\n                // Make it a relative path so that on platforms with extremely tight argument\n                // limits (like Windows), we become immune to someone cloning the repo\n                // 50 directories deep.\n                let file = file?;\n                let file = file.strip_prefix(&self.miri_dir)?;\n                cmd = cmd.arg(file);\n            }\n\n            // Run rustfmt.\n            // We want our own error message, repeating the command is too much.\n            cmd.quiet().run().map_err(|_| anyhow!(\"`rustfmt` failed\"))?;\n        }\n\n        Ok(())\n    }\n}\n","sourceCodeStart":278,"sourceCodeEnd":302,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/tools/miri/miri-script/src/util.rs#L278-L302","documentation":"Returned by format_files when the underlying rustfmt subprocess exits non-zero. The wrapper deliberately suppresses the verbose command (\"repeating the command is too much\") and replaces any error with this short message via map_err.","triggerScenarios":"Calling format_files (miri-script fmt, or any path formatting files) where rustfmt rejects a file — syntax error, an unstable feature not enabled by --unstable-features, edition mismatch, or a rustfmt config incompatibility.","commonSituations":"A file with a syntax error rustfmt can't parse; using a stable rustfmt that lacks a nightly feature referenced by the config; --edition mismatch (script hardcodes --edition=2024); a rustfmt.toml from a newer rustfmt version.","solutions":["Re-run the rustfmt command manually without .quiet() to see the real diagnostic — drop the map_err to surface the underlying io::Error.","Fix any syntax error in the offending file first.","Make sure the +{toolchain} rustfmt is a nightly that supports the configured unstable features.","Align rustfmt.toml options with the installed rustfmt version."],"exampleFix":"// before: error is swallowed into a generic string\ncmd.quiet().run().map_err(|_| anyhow!(\"`rustfmt` failed\"))?;\n\n// after: keep the command terse in logs but preserve the cause\nmatch cmd.quiet().run() {\n    Ok(()) => Ok(()),\n    Err(e) => Err(anyhow::Error::new(e)\n        .context(\"`rustfmt` failed (re-run without .quiet() to see the file it rejected)\")),\n}","handlingStrategy":"validation","validationCode":"// Dry-run rustfmt on a single file to surface the real error before batch formatting:\nfn rustfmt_ok(toolchain: &str, file: &Path) -> bool {\n    std::process::Command::new(\"rustfmt\")\n        .arg(format!(\"+{toolchain}\")).arg(\"--check\").arg(file)\n        .output().map(|o| o.status.success()).unwrap_or(false)\n}","typeGuard":"null","tryCatchPattern":"// Preserve the underlying error so the user sees which file failed:\nmatch util.format_files(files, cfg, flags) {\n    Ok(()) => Ok(()),\n    Err(e) if e.to_string().contains(\"rustfmt` failed\") => {\n        eprintln!(\"rustfmt rejected a file; re-run manually without .quiet() to see which\");\n        Err(e)\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Use a nightly rustfmt matching the configured unstable features.","Run `rustfmt --check` locally before invoking the batch formatter.","Keep rustfmt.toml options compatible with the installed rustfmt."],"tags":["miri","rustfmt","formatting","subprocess"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}