Skip to content

Commit 6704bd4

Browse files
authored
fix: ignore rustfmt output on error status (bram209#89)
1 parent 18c4b27 commit 6704bd4

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

cli/src/main.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fn main() {
101101
mut formatted,
102102
}) => {
103103
if args.rustfmt {
104-
formatted = run_rustfmt(&formatted);
104+
formatted = run_rustfmt(&formatted).unwrap_or(formatted);
105105
}
106106

107107
if args.check && check_if_diff(None, &original, &formatted, true) {
@@ -265,7 +265,7 @@ fn load_config(path: &PathBuf) -> anyhow::Result<FormatterSettings> {
265265
Ok(settings)
266266
}
267267

268-
fn run_rustfmt(source: &str) -> String {
268+
fn run_rustfmt(source: &str) -> Option<String> {
269269
let mut child = process::Command::new("rustfmt")
270270
.stdin(Stdio::piped())
271271
.stdout(Stdio::piped())
@@ -280,5 +280,10 @@ fn run_rustfmt(source: &str) -> String {
280280
.expect("failed to write to stdin");
281281

282282
let output = child.wait_with_output().expect("failed to read stdout");
283-
String::from_utf8(output.stdout).expect("stdout is not valid utf8")
283+
284+
if output.status.success() {
285+
Some(String::from_utf8(output.stdout).expect("stdout is not valid utf8"))
286+
} else {
287+
None
288+
}
284289
}

0 commit comments

Comments
 (0)