Skip to content

Commit

Permalink
Added error handling to wasm-bindgen install check.
Browse files Browse the repository at this point in the history
  • Loading branch information
data-pup committed Apr 25, 2018
1 parent f3f365e commit 4fb97c3
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static PATH_SEP: &str = ";";
static PATH_SEP: &str = ":";

pub fn cargo_install_wasm_bindgen() -> Result<(), Error> {
if wasm_bindgen_installed() {
if wasm_bindgen_installed()? {
return Ok(());
}
let step = format!(
Expand Down Expand Up @@ -63,15 +63,13 @@ pub fn wasm_bindgen_build(path: &str, name: &str) -> Result<(), Error> {
}
}

fn wasm_bindgen_installed() -> bool {
if let Ok(path) = env::var("PATH") {
path.split(PATH_SEP)
.map(|p: &str| -> bool {
let prog_str = format!("{}/wasm-bindgen", p);
fs::metadata(prog_str).is_ok()
})
.fold(false, |res, b| res || b)
} else {
false
}
fn wasm_bindgen_installed() -> Result<bool, Error> {
let path = env::var("PATH")?;
let is_installed = path.split(PATH_SEP)
.map(|p: &str| -> bool {
let prog_str = format!("{}/wasm-bindgen", p);
fs::metadata(prog_str).is_ok()
})
.fold(false, |res, b| res || b);
Ok(is_installed)
}

0 comments on commit 4fb97c3

Please sign in to comment.