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

Add exit_status to cli error to fix #291 #387

Merged
merged 1 commit into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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(())
}
Expand Down
26 changes: 14 additions & 12 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand All @@ -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(())
}
Expand All @@ -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(())
}
Expand Down
14 changes: 12 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use curl;
use serde_json;
use std::borrow::Cow;
use std::io;
use std::process::ExitStatus;
use toml;
use zip;

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
})
}

Expand Down Expand Up @@ -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"
Expand Down
10 changes: 7 additions & 3 deletions src/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand All @@ -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(())
}
Expand Down Expand Up @@ -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(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down