Skip to content

Commit

Permalink
Provide better error information if rustfmt fails.
Browse files Browse the repository at this point in the history
This uses ProcessBuilder which provides much better error information
(stdout and stderr).  It's also less code, which is a bonus.
  • Loading branch information
ehuss committed Aug 2, 2022
1 parent 15f9c2d commit f62ce1e
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use std::collections::BTreeMap;
use std::fmt;
use std::io::{BufRead, BufReader, ErrorKind};
use std::path::{Path, PathBuf};
use std::process::Command;
use std::str::{from_utf8, FromStr};
use std::str::FromStr;
use toml_edit::easy as toml;

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

// Format the newly created source file
match Command::new("rustfmt").arg(&path_of_source_file).output() {
Err(e) => log::warn!("failed to call rustfmt: {}", e),
Ok(output) => {
if !output.status.success() {
log::warn!("rustfmt failed: {:?}", from_utf8(&output.stdout));
}
}
};
if let Err(e) = cargo_util::ProcessBuilder::new("rustfmt")
.arg(&path_of_source_file)
.exec_with_output()
{
log::warn!("failed to call rustfmt: {:#}", e);
}
}
}

Expand Down

0 comments on commit f62ce1e

Please sign in to comment.