From 352b47d732f9a6c92663f58830838edd45b31133 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Tue, 30 Oct 2018 14:38:36 +0100 Subject: [PATCH 1/3] Provide better error context for `cargo build` --- src/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build.rs b/src/build.rs index f539744c..cb8f95b5 100644 --- a/src/build.rs +++ b/src/build.rs @@ -82,7 +82,7 @@ pub fn cargo_build_wasm( cmd.arg("--release"); } cmd.arg("--target").arg("wasm32-unknown-unknown"); - child::run(log, cmd, "cargo build").context("Compiling your crate to WebAssembly")?; + child::run(log, cmd, "cargo build").context("Compiling your crate to WebAssembly failed")?; Ok(()) } From b16660375ef6585f3bb59913fe1dc20427afd7ce Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Tue, 30 Oct 2018 14:38:57 +0100 Subject: [PATCH 2/3] Add "Error:" prefix to error messages --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index c9295396..0af82966 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ mod installer; fn main() { setup_panic!(); if let Err(e) = run() { - eprintln!("{}", e); + eprintln!("Error: {}", e); for cause in e.iter_causes() { eprintln!("Caused by: {}", cause); } From 1bbc966240bff22427863c23ec492c8ec167f196 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Tue, 30 Oct 2018 14:40:05 +0100 Subject: [PATCH 3/3] Don't print stdout/stderr in error messages because we already pipe that to console when running the child process Fixes #422 --- src/child.rs | 3 +-- src/error.rs | 13 +++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/child.rs b/src/child.rs index 9b45d70f..23c3f4c3 100644 --- a/src/child.rs +++ b/src/child.rs @@ -171,7 +171,6 @@ pub fn run( if exit.success() { return Ok(stdout); } else { - let msg = format!("`{}` did not exit successfully", command_name); - return Err(Error::cli(&msg, stdout.into(), stderr.into(), exit).into()); + return Err(Error::cli(command_name, stdout.into(), stderr.into(), exit).into()); } } diff --git a/src/error.rs b/src/error.rs index 75c43b30..1c2f2c49 100644 --- a/src/error.rs +++ b/src/error.rs @@ -47,13 +47,10 @@ pub enum Error { }, /// An error invoking another CLI tool. - #[fail( - display = "Process exited with {}: {}.\n\nstdout:{}\n\nstderr:\n\n{}", - exit_status, message, stdout, stderr - )] + #[fail(display = "`{}` exited with {}", tool, exit_status)] Cli { /// Error message. - message: String, + tool: String, /// The underlying CLI's `stdout` output. stdout: String, /// The underlying CLI's `stderr` output. @@ -101,9 +98,9 @@ pub enum Error { impl Error { /// Construct a CLI error. - pub fn cli(message: &str, stdout: Cow, stderr: Cow, exit_status: ExitStatus) -> Self { + pub fn cli(tool: &str, stdout: Cow, stderr: Cow, exit_status: ExitStatus) -> Self { Error::Cli { - message: message.to_string(), + tool: tool.to_string(), stdout: stdout.to_string(), stderr: stderr.to_string(), exit_status, @@ -161,7 +158,7 @@ impl Error { local_minor_version: _, } => "Your rustc version is not supported. Please install version 1.30.0 or higher.", Error::Cli { - message: _, + tool: _, stdout: _, stderr: _, exit_status: _,