Skip to content

Commit f62ce1e

Browse files
committed
Provide better error information if rustfmt fails.
This uses ProcessBuilder which provides much better error information (stdout and stderr). It's also less code, which is a bonus.
1 parent 15f9c2d commit f62ce1e

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/cargo/ops/cargo_new.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use std::collections::BTreeMap;
1010
use std::fmt;
1111
use std::io::{BufRead, BufReader, ErrorKind};
1212
use std::path::{Path, PathBuf};
13-
use std::process::Command;
14-
use std::str::{from_utf8, FromStr};
13+
use std::str::FromStr;
1514
use toml_edit::easy as toml;
1615

1716
#[derive(Clone, Copy, Debug, PartialEq)]
@@ -830,14 +829,12 @@ mod tests {
830829
paths::write(&path_of_source_file, default_file_content)?;
831830

832831
// Format the newly created source file
833-
match Command::new("rustfmt").arg(&path_of_source_file).output() {
834-
Err(e) => log::warn!("failed to call rustfmt: {}", e),
835-
Ok(output) => {
836-
if !output.status.success() {
837-
log::warn!("rustfmt failed: {:?}", from_utf8(&output.stdout));
838-
}
839-
}
840-
};
832+
if let Err(e) = cargo_util::ProcessBuilder::new("rustfmt")
833+
.arg(&path_of_source_file)
834+
.exec_with_output()
835+
{
836+
log::warn!("failed to call rustfmt: {:#}", e);
837+
}
841838
}
842839
}
843840

0 commit comments

Comments
 (0)