Skip to content

Switch from failure to anyhow #1851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,6 @@ wasm-bindgen = { path = '.' }
wasm-bindgen-futures = { path = 'crates/futures' }
js-sys = { path = 'crates/js-sys' }
web-sys = { path = 'crates/web-sys' }

walrus = { git = 'https://github.com/rustwasm/walrus' }
wasm-webidl-bindings = { git = 'https://github.com/rustwasm/wasm-webidl-bindings' }
4 changes: 2 additions & 2 deletions crates/anyref-xform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ Internal anyref transformations for wasm-bindgen
edition = '2018'

[dependencies]
failure = "0.1"
walrus = "0.12.0"
anyhow = "1.0"
walrus = "0.13.0"
21 changes: 11 additions & 10 deletions crates/anyref-xform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
//! goal at least is to have valid wasm modules coming in that don't use
//! `anyref` and valid wasm modules going out which use `anyref` at the fringes.

use failure::{bail, format_err, Error};
use anyhow::{anyhow, bail, Error};
use std::cmp;
use std::collections::{BTreeMap, HashMap, HashSet};
use walrus::ir::*;
use walrus::{ExportId, ImportId, TypeId};
use walrus::{ExportId, ImportId, InstrLocId, TypeId};
use walrus::{FunctionId, GlobalId, InitExpr, Module, TableId, ValType};

// must be kept in sync with src/lib.rs and ANYREF_HEAP_START
Expand Down Expand Up @@ -185,9 +185,8 @@ impl Context {
_ => {}
}
}
let heap_alloc = heap_alloc.ok_or_else(|| format_err!("failed to find heap alloc"))?;
let heap_dealloc =
heap_dealloc.ok_or_else(|| format_err!("failed to find heap dealloc"))?;
let heap_alloc = heap_alloc.ok_or_else(|| anyhow!("failed to find heap alloc"))?;
let heap_dealloc = heap_dealloc.ok_or_else(|| anyhow!("failed to find heap dealloc"))?;

// Create a shim function that looks like:
//
Expand Down Expand Up @@ -624,7 +623,7 @@ impl Transform<'_> {
impl VisitorMut for Rewrite<'_, '_> {
fn start_instr_seq_mut(&mut self, seq: &mut InstrSeq) {
for i in (0..seq.instrs.len()).rev() {
let call = match &mut seq.instrs[i] {
let call = match &mut seq.instrs[i].0 {
Instr::Call(call) => call,
_ => continue,
};
Expand All @@ -644,24 +643,26 @@ impl Transform<'_> {
match intrinsic {
Intrinsic::TableGrow => {
// Switch this to a `table.grow` instruction...
seq.instrs[i] = TableGrow {
seq.instrs[i].0 = TableGrow {
table: self.xform.table,
}
.into();
// ... and then insert a `ref.null` before the
// preceding instruction as the value to grow the
// table with.
seq.instrs.insert(i - 1, RefNull {}.into());
seq.instrs
.insert(i - 1, (RefNull {}.into(), InstrLocId::default()));
}
Intrinsic::TableSetNull => {
// Switch this to a `table.set` instruction...
seq.instrs[i] = TableSet {
seq.instrs[i].0 = TableSet {
table: self.xform.table,
}
.into();
// ... and then insert a `ref.null` as the
// preceding instruction
seq.instrs.insert(i, RefNull {}.into());
seq.instrs
.insert(i, (RefNull {}.into(), InstrLocId::default()));
}
Intrinsic::DropRef => call.func = self.xform.heap_dealloc,
Intrinsic::CloneRef => call.func = self.xform.clone_ref,
Expand Down
4 changes: 2 additions & 2 deletions crates/cli-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ edition = '2018'

[dependencies]
base64 = "0.9"
failure = "0.1.2"
anyhow = "1.0"
log = "0.4"
rustc-demangle = "0.1.13"
serde_json = "1.0"
tempfile = "3.0"
walrus = "0.12.0"
walrus = "0.13.0"
wasm-bindgen-anyref-xform = { path = '../anyref-xform', version = '=0.2.53' }
wasm-bindgen-shared = { path = "../shared", version = '=0.2.53' }
wasm-bindgen-multi-value-xform = { path = '../multi-value-xform', version = '=0.2.53' }
Expand Down
2 changes: 1 addition & 1 deletion crates/cli-support/src/anyref.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::webidl::{NonstandardIncoming, NonstandardOutgoing};
use crate::webidl::{NonstandardWebidlSection, WasmBindgenAux};
use failure::Error;
use anyhow::Error;
use std::collections::HashSet;
use walrus::Module;
use wasm_bindgen_anyref_xform::Context;
Expand Down
2 changes: 1 addition & 1 deletion crates/cli-support/src/descriptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! functions.

use crate::descriptor::{Closure, Descriptor};
use failure::Error;
use anyhow::Error;
use std::borrow::Cow;
use std::collections::{HashMap, HashSet};
use walrus::ImportId;
Expand Down
2 changes: 1 addition & 1 deletion crates/cli-support/src/js/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::js::incoming;
use crate::js::outgoing;
use crate::js::Context;
use crate::webidl::Binding;
use failure::{bail, Error};
use anyhow::{bail, Error};
use std::collections::HashSet;
use wasm_webidl_bindings::ast;

Expand Down
2 changes: 1 addition & 1 deletion crates/cli-support/src/js/incoming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::descriptor::VectorKind;
use crate::js::binding::JsBuilder;
use crate::js::Context;
use crate::webidl::NonstandardIncoming;
use failure::{bail, Error};
use anyhow::{bail, Error};
use wasm_webidl_bindings::ast;

pub struct Incoming<'a, 'b> {
Expand Down
6 changes: 3 additions & 3 deletions crates/cli-support/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::webidl::{AuxEnum, AuxExport, AuxExportKind, AuxImport, AuxStruct};
use crate::webidl::{AuxValue, Binding};
use crate::webidl::{JsImport, JsImportName, NonstandardWebidlSection, WasmBindgenAux};
use crate::{Bindgen, EncodeInto, OutputMode};
use failure::{bail, Error, ResultExt};
use anyhow::{bail, Context as _, Error};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::fs;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -1888,7 +1888,7 @@ impl<'a> Context<'a> {
check_duplicated_getter_and_setter_names(&pairs)?;
for (id, export) in pairs {
self.generate_export(*id, export, bindings)
.with_context(|_| {
.with_context(|| {
format!(
"failed to generate bindings for Rust export `{}`",
export.debug_name,
Expand All @@ -1901,7 +1901,7 @@ impl<'a> Context<'a> {
let catch = aux.imports_with_catch.contains(&id);
let assert_no_shim = aux.imports_with_assert_no_shim.contains(&id);
self.generate_import(*id, import, bindings, variadic, catch, assert_no_shim)
.with_context(|_| {
.with_context(|| {
format!("failed to generate bindings for import `{:?}`", import,)
})?;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cli-support/src/js/outgoing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::descriptor::VectorKind;
use crate::js::binding::JsBuilder;
use crate::js::Context;
use crate::webidl::NonstandardOutgoing;
use failure::{bail, Error};
use anyhow::{bail, Error};
use wasm_webidl_bindings::ast;

pub struct Outgoing<'a, 'b> {
Expand Down
28 changes: 14 additions & 14 deletions crates/cli-support/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![doc(html_root_url = "https://docs.rs/wasm-bindgen-cli-support/0.2")]

use failure::{bail, Error, ResultExt};
use anyhow::{bail, Context, Error};
use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::env;
use std::fs;
Expand Down Expand Up @@ -256,7 +256,7 @@ impl Bindgen {
}
Input::Path(ref path) => {
let contents = fs::read(&path)
.with_context(|_| format!("failed to read `{}`", path.display()))?;
.with_context(|| format!("failed to read `{}`", path.display()))?;
let module = walrus::ModuleConfig::new()
// Skip validation of the module as LLVM's output is
// generally already well-formed and so we won't gain much
Expand Down Expand Up @@ -307,7 +307,7 @@ impl Bindgen {

self.threads
.run(&mut module)
.with_context(|_| "failed to prepare module for threading")?;
.with_context(|| "failed to prepare module for threading")?;

// If requested, turn all mangled symbols into prettier unmangled
// symbols with the help of `rustc-demangle`.
Expand Down Expand Up @@ -373,10 +373,10 @@ impl Bindgen {
.context("failed to transform return pointers into multi-value Wasm")?;
}
webidl::standard::add_section(&mut module, &aux, &bindings)
.with_context(|_| "failed to generate a standard wasm bindings custom section")?;
.with_context(|| "failed to generate a standard wasm bindings custom section")?;
} else {
if self.multi_value {
failure::bail!(
anyhow::bail!(
"Wasm multi-value is currently only available when \
Wasm interface types is also enabled"
);
Expand Down Expand Up @@ -565,11 +565,11 @@ impl Output {
&self.module
}

pub fn emit(&self, out_dir: impl AsRef<Path>) -> Result<(), Error> {
pub fn emit(&mut self, out_dir: impl AsRef<Path>) -> Result<(), Error> {
self._emit(out_dir.as_ref())
}

fn _emit(&self, out_dir: &Path) -> Result<(), Error> {
fn _emit(&mut self, out_dir: &Path) -> Result<(), Error> {
let wasm_name = if self.wasm_interface_types {
self.stem.clone()
} else {
Expand All @@ -579,7 +579,7 @@ impl Output {
fs::create_dir_all(out_dir)?;
let wasm_bytes = self.module.emit_wasm();
fs::write(&wasm_path, wasm_bytes)
.with_context(|_| format!("failed to write `{}`", wasm_path.display()))?;
.with_context(|| format!("failed to write `{}`", wasm_path.display()))?;

if self.wasm_interface_types {
return Ok(());
Expand All @@ -593,15 +593,15 @@ impl Output {
let path = out_dir.join("snippets").join(identifier).join(name);
fs::create_dir_all(path.parent().unwrap())?;
fs::write(&path, js)
.with_context(|_| format!("failed to write `{}`", path.display()))?;
.with_context(|| format!("failed to write `{}`", path.display()))?;
}
}

for (path, contents) in self.local_modules.iter() {
let path = out_dir.join("snippets").join(path);
fs::create_dir_all(path.parent().unwrap())?;
fs::write(&path, contents)
.with_context(|_| format!("failed to write `{}`", path.display()))?;
.with_context(|| format!("failed to write `{}`", path.display()))?;
}

if self.npm_dependencies.len() > 0 {
Expand All @@ -623,26 +623,26 @@ impl Output {
};
let js_path = out_dir.join(&self.stem).with_extension(extension);
fs::write(&js_path, reset_indentation(&self.js))
.with_context(|_| format!("failed to write `{}`", js_path.display()))?;
.with_context(|| format!("failed to write `{}`", js_path.display()))?;

if self.typescript {
let ts_path = js_path.with_extension("d.ts");
fs::write(&ts_path, &self.ts)
.with_context(|_| format!("failed to write `{}`", ts_path.display()))?;
.with_context(|| format!("failed to write `{}`", ts_path.display()))?;
}

if self.mode.nodejs() {
let js_path = wasm_path.with_extension(extension);
let shim = self.generate_node_wasm_import(&self.module, &wasm_path);
fs::write(&js_path, shim)
.with_context(|_| format!("failed to write `{}`", js_path.display()))?;
.with_context(|| format!("failed to write `{}`", js_path.display()))?;
}

if self.typescript {
let ts_path = wasm_path.with_extension("d.ts");
let ts = wasm2es6js::typescript(&self.module)?;
fs::write(&ts_path, ts)
.with_context(|_| format!("failed to write `{}`", ts_path.display()))?;
.with_context(|| format!("failed to write `{}`", ts_path.display()))?;
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/cli-support/src/wasm2es6js.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use failure::{bail, Error};
use anyhow::{bail, Error};
use std::collections::HashSet;
use walrus::Module;

Expand Down
2 changes: 1 addition & 1 deletion crates/cli-support/src/webidl/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::descriptor::Function;
use crate::webidl::incoming::IncomingBuilder;
use crate::webidl::outgoing::OutgoingBuilder;
use crate::webidl::{Binding, NonstandardWebidlSection};
use failure::{format_err, Error};
use anyhow::{format_err, Error};
use walrus::{FunctionId, Module, ValType};
use wasm_webidl_bindings::ast;

Expand Down
2 changes: 1 addition & 1 deletion crates/cli-support/src/webidl/incoming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! the `outgoing.rs` module.

use crate::descriptor::{Descriptor, VectorKind};
use failure::{bail, format_err, Error};
use anyhow::{bail, format_err, Error};
use walrus::ValType;
use wasm_webidl_bindings::ast;

Expand Down
6 changes: 3 additions & 3 deletions crates/cli-support/src/webidl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::decode;
use crate::descriptor::{Descriptor, Function};
use crate::descriptors::WasmBindgenDescriptorsSection;
use crate::intrinsic::Intrinsic;
use failure::{bail, format_err, Error};
use anyhow::{anyhow, bail, Error};
use std::borrow::Cow;
use std::collections::{HashMap, HashSet};
use std::path::PathBuf;
Expand Down Expand Up @@ -1340,7 +1340,7 @@ impl<'a> Context<'a> {
walrus::ExportItem::Function(f) => f == bind.func,
_ => false,
})
.ok_or_else(|| format_err!("missing export function for webidl binding"))?;
.ok_or_else(|| anyhow!("missing export function for webidl binding"))?;
let id = export.id();
self.standard_export(binding, id)?;
}
Expand All @@ -1363,7 +1363,7 @@ impl<'a> Context<'a> {
let binding: &ast::FunctionBinding = std
.bindings
.get(bind.binding)
.ok_or_else(|| format_err!("bad binding id"))?;
.ok_or_else(|| anyhow!("bad binding id"))?;
let (wasm_ty, webidl_ty, incoming, outgoing) = match binding {
ast::FunctionBinding::Export(e) => (
e.wasm_ty,
Expand Down
2 changes: 1 addition & 1 deletion crates/cli-support/src/webidl/outgoing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use crate::descriptor::{Descriptor, VectorKind};
use crate::webidl::NonstandardWebidlSection;
use failure::{bail, format_err, Error};
use anyhow::{bail, format_err, Error};
use walrus::{Module, ValType};
use wasm_webidl_bindings::ast;

Expand Down
10 changes: 5 additions & 5 deletions crates/cli-support/src/webidl/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ edition = '2018'
curl = "0.4.13"
docopt = "1.0"
env_logger = "0.7"
failure = "0.1.2"
anyhow = "1.0"
log = "0.4"
openssl = { version = '0.10.11', optional = true }
rouille = { version = "3.0.0", default-features = false }
serde = { version = "1.0", features = ['derive'] }
serde_derive = "1.0"
serde_json = "1.0"
walrus = { version = "0.12.0", features = ['parallel'] }
walrus = { version = "0.13.0", features = ['parallel'] }
wasm-bindgen-cli-support = { path = "../cli-support", version = "=0.2.53" }
wasm-bindgen-shared = { path = "../shared", version = "=0.2.53" }

Expand Down
Loading