refactor: Return failure::Error instead of wasm_pack::error::Error

master
Jesper Håkansson 7 years ago
parent e9276e0aab
commit e9e0fb3cba
  1. 8
      src/binaries.rs
  2. 4
      src/bindgen.rs
  3. 13
      src/test/webdriver.rs

@ -138,7 +138,7 @@ pub fn install_binaries_from_targz_at_url<'a, I>(
crate_path: &Path, crate_path: &Path,
url: &str, url: &str,
binaries: I, binaries: I,
) -> Result<(), Error> ) -> Result<(), failure::Error>
where where
I: IntoIterator<Item = &'a str>, I: IntoIterator<Item = &'a str>,
{ {
@ -175,7 +175,7 @@ where
.map(|s| s.to_string_lossy()) .map(|s| s.to_string_lossy())
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", "), .join(", "),
))) )).into())
} }
} }
@ -186,7 +186,7 @@ pub fn install_binaries_from_zip_at_url<'a, I>(
crate_path: &Path, crate_path: &Path,
url: &str, url: &str,
binaries: I, binaries: I,
) -> Result<(), Error> ) -> Result<(), failure::Error>
where where
I: IntoIterator<Item = &'a str>, I: IntoIterator<Item = &'a str>,
{ {
@ -226,7 +226,7 @@ where
.map(|s| s.to_string_lossy()) .map(|s| s.to_string_lossy())
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", "), .join(", "),
))) )).into())
} }
} }

@ -55,7 +55,7 @@ pub fn install_wasm_bindgen(
} }
/// Download a tarball containing a pre-built `wasm-bindgen` binary. /// Download a tarball containing a pre-built `wasm-bindgen` binary.
pub fn download_prebuilt_wasm_bindgen(root_path: &Path, version: &str) -> Result<(), Error> { pub fn download_prebuilt_wasm_bindgen(root_path: &Path, version: &str) -> Result<(), failure::Error> {
let target = if target::LINUX && target::x86_64 { let target = if target::LINUX && target::x86_64 {
"x86_64-unknown-linux-musl" "x86_64-unknown-linux-musl"
} else if target::MACOS && target::x86_64 { } else if target::MACOS && target::x86_64 {
@ -65,7 +65,7 @@ pub fn download_prebuilt_wasm_bindgen(root_path: &Path, version: &str) -> Result
} else { } else {
return Err(Error::unsupported( return Err(Error::unsupported(
"there are no pre-built `wasm-bindgen` binaries for this target", "there are no pre-built `wasm-bindgen` binaries for this target",
)); ).into());
}; };
let url = format!( let url = format!(

@ -5,6 +5,7 @@ use binaries::{
}; };
use command::build::BuildMode; use command::build::BuildMode;
use error::Error; use error::Error;
use failure;
use slog::Logger; use slog::Logger;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use target; use target;
@ -15,7 +16,7 @@ pub fn get_or_install_chromedriver(
log: &Logger, log: &Logger,
crate_path: &Path, crate_path: &Path,
mode: BuildMode, mode: BuildMode,
) -> Result<PathBuf, Error> { ) -> Result<PathBuf, failure::Error> {
match (mode, bin_path(log, crate_path, "chromedriver")) { match (mode, bin_path(log, crate_path, "chromedriver")) {
(_, Some(path)) => Ok(path), (_, Some(path)) => Ok(path),
(BuildMode::Normal, None) => install_chromedriver(crate_path), (BuildMode::Normal, None) => install_chromedriver(crate_path),
@ -24,7 +25,7 @@ pub fn get_or_install_chromedriver(
"No crate-local `chromedriver` binary found, and could not find a global \ "No crate-local `chromedriver` binary found, and could not find a global \
`chromedriver` on the `$PATH`. Not installing `chromedriver` because of noinstall \ `chromedriver` on the `$PATH`. Not installing `chromedriver` because of noinstall \
mode.", mode.",
)), ).into()),
} }
} }
@ -52,7 +53,7 @@ fn get_chromedriver_url() -> Result<String, Error> {
} }
/// Download and install a pre-built `chromedriver` binary. /// Download and install a pre-built `chromedriver` binary.
pub fn install_chromedriver(crate_path: &Path) -> Result<PathBuf, Error> { pub fn install_chromedriver(crate_path: &Path) -> Result<PathBuf, failure::Error> {
let url = get_chromedriver_url()?; let url = get_chromedriver_url()?;
install_binaries_from_zip_at_url(crate_path, &url, Some("chromedriver"))?; install_binaries_from_zip_at_url(crate_path, &url, Some("chromedriver"))?;
let chromedriver = get_local_chromedriver_path(crate_path); let chromedriver = get_local_chromedriver_path(crate_path);
@ -66,7 +67,7 @@ pub fn get_or_install_geckodriver(
log: &Logger, log: &Logger,
crate_path: &Path, crate_path: &Path,
mode: BuildMode, mode: BuildMode,
) -> Result<PathBuf, Error> { ) -> Result<PathBuf, failure::Error> {
match (mode, bin_path(log, crate_path, "geckodriver")) { match (mode, bin_path(log, crate_path, "geckodriver")) {
(_, Some(path)) => Ok(path), (_, Some(path)) => Ok(path),
(BuildMode::Normal, None) => install_geckodriver(crate_path), (BuildMode::Normal, None) => install_geckodriver(crate_path),
@ -74,7 +75,7 @@ pub fn get_or_install_geckodriver(
(BuildMode::Noinstall, None) => Err(Error::crate_config( (BuildMode::Noinstall, None) => Err(Error::crate_config(
"No crate-local `geckodriver` binary found, and could not find a global `geckodriver` \ "No crate-local `geckodriver` binary found, and could not find a global `geckodriver` \
on the `$PATH`. Not installing `geckodriver` because of noinstall mode.", on the `$PATH`. Not installing `geckodriver` because of noinstall mode.",
)), ).into()),
} }
} }
@ -107,7 +108,7 @@ fn get_local_geckodriver_path(crate_path: &Path) -> PathBuf {
} }
/// Download and install a pre-built `geckodriver` binary. /// Download and install a pre-built `geckodriver` binary.
pub fn install_geckodriver(crate_path: &Path) -> Result<PathBuf, Error> { pub fn install_geckodriver(crate_path: &Path) -> Result<PathBuf, failure::Error> {
let url = get_geckodriver_url()?; let url = get_geckodriver_url()?;
if url.ends_with("tar.gz") { if url.ends_with("tar.gz") {

Loading…
Cancel
Save