Merge pull request #387 from konstin/exit_status

Add exit_status to cli error to fix #291
master
Nick Fitzgerald 7 years ago committed by GitHub
commit 210bf075be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/bindgen.rs
  2. 26
      src/build.rs
  3. 14
      src/error.rs
  4. 10
      src/npm.rs
  5. 2
      src/test/mod.rs

@ -97,6 +97,7 @@ pub fn cargo_install_wasm_bindgen(crate_path: &Path, version: &str) -> Result<()
Err(Error::Cli { Err(Error::Cli {
message, message,
stderr: s.to_string(), stderr: s.to_string(),
exit_status: output.status,
}) })
} else { } else {
assert!(binaries::local_bin_path(crate_path, "wasm-bindgen").is_file()); assert!(binaries::local_bin_path(crate_path, "wasm-bindgen").is_file());
@ -155,7 +156,7 @@ pub fn wasm_bindgen_build(
let output = cmd.output()?; let output = cmd.output()?;
if !output.status.success() { if !output.status.success() {
let s = String::from_utf8_lossy(&output.stderr); 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 { } else {
Ok(()) Ok(())
} }

@ -64,7 +64,11 @@ pub fn rustup_add_wasm_target(step: &Step) -> Result<(), Error> {
.output()?; .output()?;
if !output.status.success() { if !output.status.success() {
let s = String::from_utf8_lossy(&output.stderr); 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 { } else {
Ok(()) 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> { pub fn cargo_build_wasm(path: &Path, debug: bool, step: &Step) -> Result<(), Error> {
let msg = format!("{}Compiling to WASM...", emoji::CYCLONE); let msg = format!("{}Compiling to WASM...", emoji::CYCLONE);
PBAR.step(step, &msg); PBAR.step(step, &msg);
let output = { let mut cmd = Command::new("cargo");
let mut cmd = Command::new("cargo"); cmd.current_dir(path).arg("build").arg("--lib");
cmd.current_dir(path).arg("build").arg("--lib"); if !debug {
if !debug { cmd.arg("--release");
cmd.arg("--release"); }
} cmd.arg("--target").arg("wasm32-unknown-unknown");
cmd.arg("--target").arg("wasm32-unknown-unknown"); let output = cmd.output()?;
cmd.output()?
};
if !output.status.success() { if !output.status.success() {
let s = String::from_utf8_lossy(&output.stderr); 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 { } else {
Ok(()) Ok(())
} }
@ -106,7 +108,7 @@ pub fn cargo_build_wasm_tests(path: &Path, debug: bool) -> Result<(), Error> {
if !output.status.success() { if !output.status.success() {
let s = String::from_utf8_lossy(&output.stderr); 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 { } else {
Ok(()) Ok(())
} }

@ -3,6 +3,7 @@ use curl;
use serde_json; use serde_json;
use std::borrow::Cow; use std::borrow::Cow;
use std::io; use std::io;
use std::process::ExitStatus;
use toml; use toml;
use zip; use zip;
@ -46,12 +47,19 @@ pub enum Error {
}, },
/// An error invoking another CLI tool. /// 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 { Cli {
/// Error message. /// Error message.
message: String, message: String,
/// The underlying CLI's `stderr` output. /// The underlying CLI's `stderr` output.
stderr: String, stderr: String,
/// The exit status of the subprocess
exit_status: ExitStatus,
}, },
/// A crate configuration error. /// A crate configuration error.
@ -93,10 +101,11 @@ pub enum Error {
impl Error { impl Error {
/// Construct a CLI error. /// Construct a CLI error.
pub fn cli(message: &str, stderr: Cow<str>) -> Result<(), Self> { pub fn cli(message: &str, stderr: Cow<str>, exit_status: ExitStatus) -> Result<(), Self> {
Err(Error::Cli { Err(Error::Cli {
message: message.to_string(), message: message.to_string(),
stderr: stderr.to_string(), stderr: stderr.to_string(),
exit_status,
}) })
} }
@ -153,6 +162,7 @@ impl Error {
Error::Cli { Error::Cli {
message: _, message: _,
stderr: _, stderr: _,
exit_status: _,
} => "There was an error while calling another CLI tool. Details:\n\n", } => "There was an error while calling another CLI tool. Details:\n\n",
Error::CrateConfig { message: _ } => { Error::CrateConfig { message: _ } => {
"There was a crate configuration error. Details:\n\n" "There was a crate configuration error. Details:\n\n"

@ -12,7 +12,7 @@ pub fn npm_pack(path: &str) -> Result<(), Error> {
let output = Command::new("npm").current_dir(path).arg("pack").output()?; let output = Command::new("npm").current_dir(path).arg("pack").output()?;
if !output.status.success() { if !output.status.success() {
let s = String::from_utf8_lossy(&output.stderr); 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 { } else {
Ok(()) Ok(())
} }
@ -38,7 +38,7 @@ pub fn npm_publish(path: &str, access: Option<Access>) -> Result<(), Error> {
if !output.status.success() { if !output.status.success() {
let s = String::from_utf8_lossy(&output.stderr); 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 { } else {
Ok(()) Ok(())
} }
@ -76,7 +76,11 @@ pub fn npm_login(
if !output.status.success() { if !output.status.success() {
let s = String::from_utf8_lossy(&output.stderr); 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 { } else {
Ok(()) Ok(())
} }

@ -40,7 +40,7 @@ where
if !output.status.success() { if !output.status.success() {
let s = String::from_utf8_lossy(&output.stderr); 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 { } else {
for line in String::from_utf8_lossy(&output.stdout).lines() { for line in String::from_utf8_lossy(&output.stdout).lines() {
info!(log, "test output: {}", line); info!(log, "test output: {}", line);

Loading…
Cancel
Save