Skip to content

Commit 506e9cf

Browse files
committed
crate_config now returns a plain Error.
1 parent cf6a2f6 commit 506e9cf

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ impl Error {
2727
}
2828
}
2929

30-
pub fn crate_config(message: &str) -> Result<(), Self> {
31-
Err(Error::CrateConfig {
30+
pub fn crate_config(message: &str) -> Self {
31+
Error::CrateConfig {
3232
message: message.to_string(),
33-
})
33+
}
3434
}
3535

3636
pub fn error_type(&self) -> String {

src/manifest.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,19 @@ pub fn get_wasm_bindgen_version(path: &str) -> Result<String, Error> {
154154
.and_then(|deps| deps.wasm_bindgen)
155155
{
156156
Some(ref version) if version.is_empty() => {
157-
let message = "\"wasm-bindgen\" dependency is missing its version number".to_string();
158-
let e = Error::CrateConfig { message };
157+
let msg = format!(
158+
"\"{}\" dependency is missing its version number",
159+
style("wasm-bindgen").bold().dim()
160+
);
161+
let e = Error::crate_config(&msg);
159162
Err(e)
160163
}
161164
Some(version) => Ok(version),
162165
None => {
163-
let message = format!(
166+
let msg = format!(
164167
"Ensure that you have \"{}\" as a dependency in your Cargo.toml file:\n[dependencies]\nwasm-bindgen = \"0.2\"",
165168
style("wasm-bindgen").bold().dim());
166-
let e = Error::CrateConfig { message };
169+
let e = Error::crate_config(&msg);
167170
Err(e)
168171
}
169172
}
@@ -187,9 +190,10 @@ fn check_crate_type(path: &str) -> Result<(), Error> {
187190
lib.crate_type
188191
.map_or(false, |types| types.iter().any(|s| s == "cdylib"))
189192
}) {
190-
return Ok(());
193+
Ok(())
194+
} else {
195+
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\"]";
196+
let e = Error::crate_config(msg);
197+
Err(e)
191198
}
192-
Error::crate_config(
193-
"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\"]"
194-
)
195199
}

0 commit comments

Comments
 (0)