diff --git a/src/bindgen.rs b/src/bindgen.rs index a1a1e5ff..715bcfa5 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -97,6 +97,7 @@ pub fn cargo_install_wasm_bindgen(crate_path: &Path, version: &str) -> Result<() Err(Error::Cli { message, stderr: s.to_string(), + exit_status: output.status, }) } else { assert!(binaries::local_bin_path(crate_path, "wasm-bindgen").is_file()); @@ -155,7 +156,7 @@ pub fn wasm_bindgen_build( let output = cmd.output()?; if !output.status.success() { let s = String::from_utf8_lossy(&output.stderr); - Error::cli("wasm-bindgen failed to execute properly", s) + Error::cli("wasm-bindgen failed to execute properly", s, output.status) } else { Ok(()) } diff --git a/src/build.rs b/src/build.rs index aeee4109..928fc32e 100644 --- a/src/build.rs +++ b/src/build.rs @@ -64,7 +64,11 @@ pub fn rustup_add_wasm_target(step: &Step) -> Result<(), Error> { .output()?; if !output.status.success() { let s = String::from_utf8_lossy(&output.stderr); - Error::cli("Adding the wasm32-unknown-unknown target failed", s) + Error::cli( + "Adding the wasm32-unknown-unknown target failed", + s, + output.status, + ) } else { Ok(()) } @@ -74,19 +78,17 @@ pub fn rustup_add_wasm_target(step: &Step) -> Result<(), Error> { pub fn cargo_build_wasm(path: &Path, debug: bool, step: &Step) -> Result<(), Error> { let msg = format!("{}Compiling to WASM...", emoji::CYCLONE); PBAR.step(step, &msg); - let output = { - let mut cmd = Command::new("cargo"); - cmd.current_dir(path).arg("build").arg("--lib"); - if !debug { - cmd.arg("--release"); - } - cmd.arg("--target").arg("wasm32-unknown-unknown"); - cmd.output()? - }; + let mut cmd = Command::new("cargo"); + cmd.current_dir(path).arg("build").arg("--lib"); + if !debug { + cmd.arg("--release"); + } + cmd.arg("--target").arg("wasm32-unknown-unknown"); + let output = cmd.output()?; if !output.status.success() { let s = String::from_utf8_lossy(&output.stderr); - Error::cli("Compilation of your program failed", s) + Error::cli("Compilation of your program failed", s, output.status) } else { Ok(()) } @@ -106,7 +108,7 @@ pub fn cargo_build_wasm_tests(path: &Path, debug: bool) -> Result<(), Error> { if !output.status.success() { let s = String::from_utf8_lossy(&output.stderr); - Error::cli("Compilation of your program failed", s) + Error::cli("Compilation of your program failed", s, output.status) } else { Ok(()) } diff --git a/src/error.rs b/src/error.rs index c5c20e7c..5b65d00e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,6 +3,7 @@ use curl; use serde_json; use std::borrow::Cow; use std::io; +use std::process::ExitStatus; use toml; use zip; @@ -46,12 +47,19 @@ pub enum Error { }, /// An error invoking another CLI tool. - #[fail(display = "{}. stderr:\n\n{}", message, stderr)] + #[fail( + display = "Process exited with {}: {}. stderr:\n\n{}", + exit_status, + message, + stderr + )] Cli { /// Error message. message: String, /// The underlying CLI's `stderr` output. stderr: String, + /// The exit status of the subprocess + exit_status: ExitStatus, }, /// A crate configuration error. @@ -93,10 +101,11 @@ pub enum Error { impl Error { /// Construct a CLI error. - pub fn cli(message: &str, stderr: Cow) -> Result<(), Self> { + pub fn cli(message: &str, stderr: Cow, exit_status: ExitStatus) -> Result<(), Self> { Err(Error::Cli { message: message.to_string(), stderr: stderr.to_string(), + exit_status, }) } @@ -153,6 +162,7 @@ impl Error { Error::Cli { message: _, stderr: _, + exit_status: _, } => "There was an error while calling another CLI tool. Details:\n\n", Error::CrateConfig { message: _ } => { "There was a crate configuration error. Details:\n\n" diff --git a/src/npm.rs b/src/npm.rs index 059480c9..d17fccbc 100644 --- a/src/npm.rs +++ b/src/npm.rs @@ -12,7 +12,7 @@ pub fn npm_pack(path: &str) -> Result<(), Error> { let output = Command::new("npm").current_dir(path).arg("pack").output()?; if !output.status.success() { let s = String::from_utf8_lossy(&output.stderr); - Error::cli("Packaging up your code failed", s) + Error::cli("Packaging up your code failed", s, output.status) } else { Ok(()) } @@ -38,7 +38,7 @@ pub fn npm_publish(path: &str, access: Option) -> Result<(), Error> { if !output.status.success() { let s = String::from_utf8_lossy(&output.stderr); - Error::cli("Publishing to npm failed", s) + Error::cli("Publishing to npm failed", s, output.status) } else { Ok(()) } @@ -76,7 +76,11 @@ pub fn npm_login( if !output.status.success() { let s = String::from_utf8_lossy(&output.stderr); - Error::cli(&format!("Login to registry {} failed", registry), s) + Error::cli( + &format!("Login to registry {} failed", registry), + s, + output.status, + ) } else { Ok(()) } diff --git a/src/test/mod.rs b/src/test/mod.rs index d182ffdd..f30100fd 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -40,7 +40,7 @@ where if !output.status.success() { let s = String::from_utf8_lossy(&output.stderr); - Error::cli("Running wasm tests failed", s) + Error::cli("Running wasm tests failed", s, output.status) } else { for line in String::from_utf8_lossy(&output.stdout).lines() { info!(log, "test output: {}", line);