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:
Alex Crichton
2019-11-04 11:35:28 -06:00
committed by GitHub
parent 913fdbc3da
commit 935f71afec
37 changed files with 131 additions and 239 deletions

View File

@ -20,7 +20,7 @@ use crate::descriptor::VectorKind;
use crate::webidl::{AuxExportKind, AuxImport, AuxValue, JsImport, JsImportName};
use crate::webidl::{NonstandardIncoming, NonstandardOutgoing};
use crate::webidl::{NonstandardWebidlSection, WasmBindgenAux};
use failure::{bail, Error, ResultExt};
use anyhow::{bail, Context, Error};
use walrus::Module;
use wasm_bindgen_multi_value_xform as multi_value_xform;
use wasm_bindgen_wasm_conventions as wasm_conventions;
@ -210,14 +210,14 @@ pub fn add_section(
}
let name = &module.exports.get(*export).name;
let params = extract_incoming(&binding.incoming).with_context(|_| {
let params = extract_incoming(&binding.incoming).with_context(|| {
format!(
"failed to map arguments for export `{}` to standard \
binding expressions",
name
)
})?;
let result = extract_outgoing(&binding.outgoing).with_context(|_| {
let result = extract_outgoing(&binding.outgoing).with_context(|| {
format!(
"failed to map return value for export `{}` to standard \
binding expressions",
@ -252,14 +252,14 @@ pub fn add_section(
let import = module.imports.get(*import);
(&import.module, &import.name)
};
let params = extract_outgoing(&binding.outgoing).with_context(|_| {
let params = extract_outgoing(&binding.outgoing).with_context(|| {
format!(
"failed to map arguments of import `{}::{}` to standard \
binding expressions",
module_name, name,
)
})?;
let result = extract_incoming(&binding.incoming).with_context(|_| {
let result = extract_incoming(&binding.incoming).with_context(|| {
format!(
"failed to map return value of import `{}::{}` to standard \
binding expressions",