Add exit_status to cli error to fix #291

master
konstin 7 years ago
parent 05151ead6d
commit 514e5c6032
  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 {
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(())
}

@ -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(())
}

@ -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<str>) -> Result<(), Self> {
pub fn cli(message: &str, stderr: Cow<str>, 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"

@ -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<Access>) -> 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(())
}

@ -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);

Loading…
Cancel
Save