Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clippy_dev: Pass stderr to CommandFailed #6656

Merged
merged 1 commit into from Jan 31, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 15 additions & 8 deletions clippy_dev/src/fmt.rs
Expand Up @@ -8,7 +8,7 @@ use walkdir::WalkDir;

#[derive(Debug)]
pub enum CliError {
CommandFailed(String),
CommandFailed(String, String),
IoError(io::Error),
RustfmtNotInstalled,
WalkDirError(walkdir::Error),
Expand Down Expand Up @@ -75,8 +75,8 @@ pub fn run(check: bool, verbose: bool) {

fn output_err(err: CliError) {
match err {
CliError::CommandFailed(command) => {
eprintln!("error: A command failed! `{}`", command);
CliError::CommandFailed(command, stderr) => {
eprintln!("error: A command failed! `{}`\nstderr: {}", command, stderr);
},
CliError::IoError(err) => {
eprintln!("error: {}", err);
Expand Down Expand Up @@ -136,12 +136,16 @@ fn exec(
println!("{}", format_command(&program, &dir, args));
}

let mut child = Command::new(&program).current_dir(&dir).args(args.iter()).spawn()?;
let code = child.wait()?;
let success = code.success();
let child = Command::new(&program).current_dir(&dir).args(args.iter()).spawn()?;
let output = child.wait_with_output()?;
let success = output.status.success();

if !context.check && !success {
return Err(CliError::CommandFailed(format_command(&program, &dir, args)));
let stderr = std::str::from_utf8(&output.stderr).unwrap_or("");
return Err(CliError::CommandFailed(
format_command(&program, &dir, args),
String::from(stderr),
));
}

Ok(success)
Expand Down Expand Up @@ -177,7 +181,10 @@ fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> {
{
Err(CliError::RustfmtNotInstalled)
} else {
Err(CliError::CommandFailed(format_command(&program, &dir, args)))
Err(CliError::CommandFailed(
format_command(&program, &dir, args),
std::str::from_utf8(&output.stderr).unwrap_or("").to_string(),
))
}
}

Expand Down