Skip to content

Commit

Permalink
crate_config now returns a plain Error.
Browse files Browse the repository at this point in the history
  • Loading branch information
data-pup committed Jun 20, 2018
1 parent cf6a2f6 commit 506e9cf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ impl Error {
}
}

pub fn crate_config(message: &str) -> Result<(), Self> {
Err(Error::CrateConfig {
pub fn crate_config(message: &str) -> Self {
Error::CrateConfig {
message: message.to_string(),
})
}
}

pub fn error_type(&self) -> String {
Expand Down
20 changes: 12 additions & 8 deletions src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,19 @@ pub fn get_wasm_bindgen_version(path: &str) -> Result<String, Error> {
.and_then(|deps| deps.wasm_bindgen)
{
Some(ref version) if version.is_empty() => {
let message = "\"wasm-bindgen\" dependency is missing its version number".to_string();
let e = Error::CrateConfig { message };
let msg = format!(
"\"{}\" dependency is missing its version number",
style("wasm-bindgen").bold().dim()
);
let e = Error::crate_config(&msg);
Err(e)
}
Some(version) => Ok(version),
None => {
let message = format!(
let msg = format!(
"Ensure that you have \"{}\" as a dependency in your Cargo.toml file:\n[dependencies]\nwasm-bindgen = \"0.2\"",
style("wasm-bindgen").bold().dim());
let e = Error::CrateConfig { message };
let e = Error::crate_config(&msg);
Err(e)
}
}
Expand All @@ -187,9 +190,10 @@ fn check_crate_type(path: &str) -> Result<(), Error> {
lib.crate_type
.map_or(false, |types| types.iter().any(|s| s == "cdylib"))
}) {
return Ok(());
Ok(())
} else {
let msg = "crate-type must be cdylib to compile to wasm32-unknown-unknown. Add the following to your Cargo.toml file:\n\n[lib]\ncrate-type = [\"cdylib\"]";
let e = Error::crate_config(msg);
Err(e)
}
Error::crate_config(
"crate-type must be cdylib to compile to wasm32-unknown-unknown. Add the following to your Cargo.toml file:\n\n[lib]\ncrate-type = [\"cdylib\"]"
)
}

0 comments on commit 506e9cf

Please sign in to comment.