mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-25 02:31:35 +00:00
Switch from failure
to anyhow
(#1851)
This commit switches all of `wasm-bindgen` from the `failure` crate to `anyhow`. The `anyhow` crate should serve all the purposes that we previously used `failure` for but has a few advantages: * It's based on the standard `Error` trait rather than a custom `Fail` trait, improving ecosystem compatibility. * We don't need a `#[derive(Fail)]`, which means that's less code to compile for `wasm-bindgen`. This notably helps the compile time of `web-sys` itself. * Using `Result<()>` in `fn main` with `anyhow::Error` produces human-readable output, so we can use that natively.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
|
||||
#![deny(missing_docs, missing_debug_implementations)]
|
||||
|
||||
use failure::{bail, format_err, Error};
|
||||
use anyhow::{anyhow, bail, Error};
|
||||
use walrus::{GlobalId, GlobalKind, MemoryId, Module, ValType};
|
||||
|
||||
/// Get a Wasm module's canonical linear memory.
|
||||
@ -22,7 +22,7 @@ pub fn get_memory(module: &Module) -> Result<MemoryId, Error> {
|
||||
);
|
||||
}
|
||||
memory.ok_or_else(|| {
|
||||
format_err!(
|
||||
anyhow!(
|
||||
"module does not have a memory; must have a memory \
|
||||
to transform return pointers into Wasm multi-value"
|
||||
)
|
||||
@ -69,9 +69,7 @@ pub fn unexport_shadow_stack_pointer(module: &mut Module) -> Result<(), Error> {
|
||||
.iter()
|
||||
.find(|e| e.name == "__shadow_stack_pointer")
|
||||
.map(|e| e.id())
|
||||
.ok_or_else(|| {
|
||||
format_err!("did not find the `__shadow_stack_pointer` export in the module")
|
||||
})?;
|
||||
.ok_or_else(|| anyhow!("did not find the `__shadow_stack_pointer` export in the module"))?;
|
||||
module.exports.delete(e);
|
||||
Ok(())
|
||||
}
|
||||
@ -85,9 +83,7 @@ pub fn get_shadow_stack_pointer(module: &Module) -> Result<GlobalId, Error> {
|
||||
.exports
|
||||
.iter()
|
||||
.find(|e| e.name == "__shadow_stack_pointer")
|
||||
.ok_or_else(|| {
|
||||
format_err!("did not find the `__shadow_stack_pointer` export in the module")
|
||||
})
|
||||
.ok_or_else(|| anyhow!("did not find the `__shadow_stack_pointer` export in the module"))
|
||||
.and_then(|e| match e.item {
|
||||
walrus::ExportItem::Global(g) => Ok(g),
|
||||
_ => bail!("`__shadow_stack_pointer` export is wrong kind"),
|
||||
|
Reference in New Issue
Block a user