Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Migrate Wizer to `wasmtime::error` (#12266)

Nick Fitzgerald228f448b0c1a
diff --git a/Cargo.lock b/Cargo.lock
index 5e0c9972d2..0a586cbe88 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5247,7 +5247,6 @@ dependencies = [
name = "wasmtime-wizer"
version = "42.0.0"
dependencies = [
- "anyhow",
"clap",
"criterion",
"env_logger 0.11.5",
diff --git a/crates/wizer/Cargo.toml b/crates/wizer/Cargo.toml
index 80ae140e3d..1caee3dd6d 100644
--- a/crates/wizer/Cargo.toml
+++ b/crates/wizer/Cargo.toml
@@ -25,14 +25,13 @@ name = "uap"
harness = false
[dependencies]
-anyhow = { workspace = true }
log = { workspace = true }
rayon = { workspace = true }
clap = { workspace = true, optional = true }
wasm-encoder = { workspace = true, features = ['wasmparser'] }
wasmparser = { workspace = true, features = ['validate', 'features'] }
wasmprinter = { workspace = true, optional = true }
-wasmtime = { workspace = true, optional = true, features = ['std', 'runtime', 'cranelift', 'cache', 'threads', 'gc', 'gc-null', 'async'] }
+wasmtime = { workspace = true }
[dev-dependencies]
criterion = { workspace = true }
@@ -49,10 +48,19 @@ tokio = { workspace = true, features = ['macros'] }
wasmprinter = ['dep:wasmprinter']
# Enables default runtime implementations based on the `wasmtime` crate.
-wasmtime = ['dep:wasmtime']
+wasmtime = [
+ 'wasmtime/std',
+ 'wasmtime/runtime',
+ 'wasmtime/cranelift',
+ 'wasmtime/cache',
+ 'wasmtime/threads',
+ 'wasmtime/gc',
+ 'wasmtime/gc-null',
+ 'wasmtime/async',
+]
# Enable support for wizening components.
-component-model = ['wasmtime?/component-model']
+component-model = ['wasmtime/component-model']
[[test]]
name = "all"
diff --git a/crates/wizer/src/component.rs b/crates/wizer/src/component.rs
index ec0385538d..ba2b76944c 100644
--- a/crates/wizer/src/component.rs
+++ b/crates/wizer/src/component.rs
@@ -1,5 +1,5 @@
use crate::Wizer;
-use anyhow::bail;
+use ::wasmtime::{Result, bail};
mod info;
mod instrument;
@@ -20,7 +20,7 @@ impl Wizer {
pub fn instrument_component<'a>(
&self,
wasm: &'a [u8],
- ) -> anyhow::Result<(ComponentContext<'a>, Vec<u8>)> {
+ ) -> Result<(ComponentContext<'a>, Vec<u8>)> {
// Make sure we're given valid Wasm from the get go.
self.wasm_validate(&wasm)?;
@@ -36,7 +36,7 @@ impl Wizer {
&self,
mut cx: ComponentContext<'_>,
instance: &mut impl ComponentInstanceState,
- ) -> anyhow::Result<Vec<u8>> {
+ ) -> Result<Vec<u8>> {
if !self.func_renames.is_empty() {
bail!("components do not support renaming functions");
}
diff --git a/crates/wizer/src/component/instrument.rs b/crates/wizer/src/component/instrument.rs
index 789a9e4cbf..6562e217a9 100644
--- a/crates/wizer/src/component/instrument.rs
+++ b/crates/wizer/src/component/instrument.rs
@@ -1,8 +1,8 @@
use crate::ModuleContext;
use crate::component::info::{Accessor, RawSection};
use crate::component::{ComponentContext, WIZER_INSTANCE};
-use anyhow::{Result, bail};
use wasm_encoder::reencode::{Reencode, RoundtripReencoder};
+use wasmtime::{Result, bail};
/// Instrumentation phase of wizening a component.
///
diff --git a/crates/wizer/src/component/parse.rs b/crates/wizer/src/component/parse.rs
index 3be39aba79..2e1449c509 100644
--- a/crates/wizer/src/component/parse.rs
+++ b/crates/wizer/src/component/parse.rs
@@ -1,10 +1,10 @@
use crate::component::ComponentContext;
-use anyhow::{Result, bail};
use std::collections::hash_map::Entry;
use wasmparser::{
CanonicalFunction, ComponentAlias, ComponentExternalKind, ComponentOuterAliasKind, Encoding,
Instance, Parser, Payload,
};
+use wasmtime::{Result, bail};
/// Parse the given Wasm bytes into a `ComponentContext` tree.
///
@@ -19,7 +19,7 @@ use wasmparser::{
/// * Component-level start functions are not supported.
///
/// Some of these restrictions are likely to be loosened over time, however.
-pub(crate) fn parse<'a>(full_wasm: &'a [u8]) -> anyhow::Result<ComponentContext<'a>> {
+pub(crate) fn parse<'a>(full_wasm: &'a [u8]) -> wasmtime::Result<ComponentContext<'a>> {
let mut component = ComponentContext::default();
let parser = Parser::new(0).parse_all(full_wasm);
parse_into(Some(&mut component), full_wasm, parser)?;
@@ -30,7 +30,7 @@ fn parse_into<'a>(
mut cx: Option<&mut ComponentContext<'a>>,
full_wasm: &'a [u8],
mut iter: impl Iterator<Item = wasmparser::Result<Payload<'a>>>,
-) -> anyhow::Result<()> {
+) -> wasmtime::Result<()> {
let mut stack = Vec::new();
while let Some(payload) = iter.next() {
let payload = payload?;
diff --git a/crates/wizer/src/component/wasmtime.rs b/crates/wizer/src/component/wasmtime.rs
index bf9f7d87e6..1f4590320a 100644
--- a/crates/wizer/src/component/wasmtime.rs
+++ b/crates/wizer/src/component/wasmtime.rs
@@ -1,10 +1,9 @@
use crate::Wizer;
use crate::component::ComponentInstanceState;
-use anyhow::{Context, anyhow};
use wasmtime::component::{
Component, ComponentExportIndex, Instance, Lift, WasmList, types::ComponentItem,
};
-use wasmtime::{Result, Store};
+use wasmtime::{Result, Store, error::Context as _, format_err};
impl Wizer {
/// Same as [`Wizer::run`], except for components.
@@ -13,7 +12,7 @@ impl Wizer {
store: &mut Store<T>,
wasm: &[u8],
instantiate: impl AsyncFnOnce(&mut Store<T>, &Component) -> Result<Instance>,
- ) -> anyhow::Result<Vec<u8>> {
+ ) -> wasmtime::Result<Vec<u8>> {
let (cx, instrumented_wasm) = self.instrument_component(wasm)?;
#[cfg(feature = "wasmprinter")]
@@ -36,19 +35,19 @@ impl Wizer {
fn validate_component_init_func(
&self,
component: &Component,
- ) -> anyhow::Result<ComponentExportIndex> {
+ ) -> wasmtime::Result<ComponentExportIndex> {
let init_func = self.get_init_func();
let (ty, index) = component
.get_export(None, init_func)
- .ok_or_else(|| anyhow!("the component does export the function `{init_func}`"))?;
+ .ok_or_else(|| format_err!("the component does export the function `{init_func}`"))?;
let ty = match ty {
ComponentItem::ComponentFunc(ty) => ty,
- _ => anyhow::bail!("the component's `{init_func}` export is not a function",),
+ _ => wasmtime::bail!("the component's `{init_func}` export is not a function",),
};
if ty.params().len() != 0 || ty.results().len() != 0 {
- anyhow::bail!(
+ wasmtime::bail!(
"the component's `{init_func}` function export does not have type `[] -> []`",
);
}
@@ -60,7 +59,7 @@ impl Wizer {
store: &mut Store<T>,
instance: &Instance,
index: ComponentExportIndex,
- ) -> anyhow::Result<()> {
+ ) -> wasmtime::Result<()> {
let init_func = instance
.get_typed_func::<(), ()>(&mut *store, index)
.expect("checked by `validate_init_func`");
diff --git a/crates/wizer/src/lib.rs b/crates/wizer/src/lib.rs
index f03b1e9d21..0f289c0be3 100644
--- a/crates/wizer/src/lib.rs
+++ b/crates/wizer/src/lib.rs
@@ -22,7 +22,7 @@ pub use component::*;
pub use crate::info::ModuleContext;
pub use crate::snapshot::SnapshotVal;
-use anyhow::Context;
+use ::wasmtime::{Result, bail, error::Context as _};
use std::collections::{HashMap, HashSet};
const DEFAULT_KEEP_INIT_FUNC: bool = false;
@@ -98,10 +98,10 @@ pub struct Wizer {
}
#[cfg(feature = "clap")]
-fn parse_rename(s: &str) -> anyhow::Result<(String, String)> {
+fn parse_rename(s: &str) -> Result<(String, String)> {
let parts: Vec<&str> = s.splitn(2, '=').collect();
if parts.len() != 2 {
- anyhow::bail!("must contain exactly one equals character ('=')");
+ bail!("must contain exactly one equals character ('=')");
}
Ok((parts[0].into(), parts[1].into()))
}
@@ -117,7 +117,7 @@ struct FuncRenames {
}
impl FuncRenames {
- fn parse(renames: &[(String, String)]) -> anyhow::Result<FuncRenames> {
+ fn parse(renames: &[(String, String)]) -> Result<FuncRenames> {
let mut ret = FuncRenames {
rename_src_to_dst: HashMap::new(),
rename_dsts: HashSet::new(),
@@ -128,10 +128,10 @@ impl FuncRenames {
for (dst, src) in renames {
if ret.rename_dsts.contains(dst) {
- anyhow::bail!("Duplicated function rename dst {dst}");
+ bail!("Duplicated function rename dst {dst}");
}
if ret.rename_src_to_dst.contains_key(src) {
- anyhow::bail!("Duplicated function rename src {src}");
+ bail!("Duplicated function rename src {src}");
}
ret.rename_dsts.insert(dst.clone());
ret.rename_src_to_dst.insert(src.clone(), dst.clone());
@@ -186,7 +186,7 @@ impl Wizer {
///
/// After the returned wasm is executed the context returned here and the
/// state of the instance should be passed to [`Self::snapshot`].
- pub fn instrument<'a>(&self, wasm: &'a [u8]) -> anyhow::Result<(ModuleContext<'a>, Vec<u8>)> {
+ pub fn instrument<'a>(&self, wasm: &'a [u8]) -> Result<(ModuleContext<'a>, Vec<u8>)> {
// Make sure we're given valid Wasm from the get go.
self.wasm_validate(&wasm)?;
@@ -197,13 +197,13 @@ impl Wizer {
for import in cx.imports() {
match import.ty {
wasmparser::TypeRef::Global(_) => {
- anyhow::bail!("imported globals are not supported")
+ bail!("imported globals are not supported")
}
wasmparser::TypeRef::Table(_) => {
- anyhow::bail!("imported tables are not supported")
+ bail!("imported tables are not supported")
}
wasmparser::TypeRef::Memory(_) => {
- anyhow::bail!("imported memories are not supported")
+ bail!("imported memories are not supported")
}
wasmparser::TypeRef::Func(_) => {}
wasmparser::TypeRef::FuncExact(_) => {}
@@ -227,7 +227,7 @@ impl Wizer {
&self,
mut cx: ModuleContext<'_>,
instance: &mut impl InstanceState,
- ) -> anyhow::Result<Vec<u8>> {
+ ) -> Result<Vec<u8>> {
// Parse rename spec.
let renames = FuncRenames::parse(&self.func_renames)?;
@@ -253,7 +253,7 @@ impl Wizer {
}
}
- fn wasm_validate(&self, wasm: &[u8]) -> anyhow::Result<()> {
+ fn wasm_validate(&self, wasm: &[u8]) -> Result<()> {
log::debug!("Validating input Wasm");
wasmparser::Validator::new_with_features(wasmparser::WasmFeatures::all())
@@ -279,19 +279,19 @@ impl Wizer {
// mutated, allowing these instructions, but that's
// also not possible at this time.
wasmparser::Operator::TableCopy { .. } => {
- anyhow::bail!("unsupported `table.copy` instruction")
+ bail!("unsupported `table.copy` instruction")
}
wasmparser::Operator::TableInit { .. } => {
- anyhow::bail!("unsupported `table.init` instruction")
+ bail!("unsupported `table.init` instruction")
}
wasmparser::Operator::TableSet { .. } => {
- anyhow::bail!("unsupported `table.set` instruction")
+ bail!("unsupported `table.set` instruction")
}
wasmparser::Operator::TableGrow { .. } => {
- anyhow::bail!("unsupported `table.grow` instruction")
+ bail!("unsupported `table.grow` instruction")
}
wasmparser::Operator::TableFill { .. } => {
- anyhow::bail!("unsupported `table.fill` instruction")
+ bail!("unsupported `table.fill` instruction")
}
// Wizer has no way of dynamically determining which
@@ -302,10 +302,10 @@ impl Wizer {
// initialization function, but that can't be done
// easily at this time.
wasmparser::Operator::ElemDrop { .. } => {
- anyhow::bail!("unsupported `elem.drop` instruction")
+ bail!("unsupported `elem.drop` instruction")
}
wasmparser::Operator::DataDrop { .. } => {
- anyhow::bail!("unsupported `data.drop` instruction")
+ bail!("unsupported `data.drop` instruction")
}
// Wizer can't snapshot GC references, so disallow
@@ -313,22 +313,22 @@ impl Wizer {
// example, reading something from a table and then
// mutating it.
wasmparser::Operator::StructSet { .. } => {
- anyhow::bail!("unsupported `struct.set` instruction")
+ bail!("unsupported `struct.set` instruction")
}
wasmparser::Operator::ArraySet { .. } => {
- anyhow::bail!("unsupported `array.set` instruction")
+ bail!("unsupported `array.set` instruction")
}
wasmparser::Operator::ArrayFill { .. } => {
- anyhow::bail!("unsupported `array.fill` instruction")
+ bail!("unsupported `array.fill` instruction")
}
wasmparser::Operator::ArrayCopy { .. } => {
- anyhow::bail!("unsupported `array.copy` instruction")
+ bail!("unsupported `array.copy` instruction")
}
wasmparser::Operator::ArrayInitData { .. } => {
- anyhow::bail!("unsupported `array.init_data` instruction")
+ bail!("unsupported `array.init_data` instruction")
}
wasmparser::Operator::ArrayInitElem { .. } => {
- anyhow::bail!("unsupported `array.init_elem` instruction")
+ bail!("unsupported `array.init_elem` instruction")
}
_ => continue,
@@ -348,9 +348,7 @@ impl Wizer {
| wasmparser::ValType::F64
| wasmparser::ValType::V128 => {}
wasmparser::ValType::Ref(_) => {
- anyhow::bail!(
- "unsupported mutable global containing a reference type"
- )
+ bail!("unsupported mutable global containing a reference type")
}
}
}
diff --git a/crates/wizer/src/parse.rs b/crates/wizer/src/parse.rs
index bc255b5be0..90e1487aa9 100644
--- a/crates/wizer/src/parse.rs
+++ b/crates/wizer/src/parse.rs
@@ -1,16 +1,16 @@
use crate::info::ModuleContext;
-use anyhow::{Context, bail};
use wasmparser::{Encoding, Parser};
+use wasmtime::{bail, error::Context as _};
/// Parse the given Wasm bytes into a `ModuleInfo` tree.
-pub(crate) fn parse<'a>(full_wasm: &'a [u8]) -> anyhow::Result<ModuleContext<'a>> {
+pub(crate) fn parse<'a>(full_wasm: &'a [u8]) -> wasmtime::Result<ModuleContext<'a>> {
parse_with(full_wasm, &mut Parser::new(0).parse_all(full_wasm))
}
pub(crate) fn parse_with<'a>(
full_wasm: &'a [u8],
payloads: &mut impl Iterator<Item = wasmparser::Result<wasmparser::Payload<'a>>>,
-) -> anyhow::Result<ModuleContext<'a>> {
+) -> wasmtime::Result<ModuleContext<'a>> {
log::debug!("Parsing the input Wasm");
let mut module = ModuleContext::default();
@@ -48,13 +48,13 @@ pub(crate) fn parse_with<'a>(
fn import_section<'a>(
module: &mut ModuleContext<'a>,
imports: wasmparser::ImportSectionReader<'a>,
-) -> anyhow::Result<()> {
+) -> wasmtime::Result<()> {
// Check that we can properly handle all imports.
for imp in imports.into_imports() {
let imp = imp?;
if imp.module.starts_with("__wizer_") || imp.name.starts_with("__wizer_") {
- anyhow::bail!(
+ wasmtime::bail!(
"input Wasm module already imports entities named with the `__wizer_*` prefix"
);
}
@@ -67,7 +67,7 @@ fn import_section<'a>(
fn function_section<'a>(
module: &mut ModuleContext<'a>,
funcs: wasmparser::FunctionSectionReader<'a>,
-) -> anyhow::Result<()> {
+) -> wasmtime::Result<()> {
for ty_idx in funcs {
module.push_function(ty_idx?);
}
@@ -77,7 +77,7 @@ fn function_section<'a>(
fn table_section<'a>(
module: &mut ModuleContext<'a>,
tables: wasmparser::TableSectionReader<'a>,
-) -> anyhow::Result<()> {
+) -> wasmtime::Result<()> {
for table in tables {
module.push_table(table?.ty);
}
@@ -87,7 +87,7 @@ fn table_section<'a>(
fn memory_section<'a>(
module: &mut ModuleContext<'a>,
mems: wasmparser::MemorySectionReader<'a>,
-) -> anyhow::Result<()> {
+) -> wasmtime::Result<()> {
for m in mems {
module.push_defined_memory(m?);
}
@@ -97,7 +97,7 @@ fn memory_section<'a>(
fn global_section<'a>(
module: &mut ModuleContext<'a>,
globals: wasmparser::GlobalSectionReader<'a>,
-) -> anyhow::Result<()> {
+) -> wasmtime::Result<()> {
for g in globals {
module.push_defined_global(g?.ty);
}
@@ -107,12 +107,12 @@ fn global_section<'a>(
fn export_section<'a>(
module: &mut ModuleContext<'a>,
exports: wasmparser::ExportSectionReader<'a>,
-) -> anyhow::Result<()> {
+) -> wasmtime::Result<()> {
for export in exports {
let export = export?;
if export.name.starts_with("__wizer_") {
- anyhow::bail!(
+ wasmtime::bail!(
"input Wasm module already exports entities named with the `__wizer_*` prefix"
);
}
diff --git a/crates/wizer/src/wasmtime.rs b/crates/wizer/src/wasmtime.rs
index 289df62304..fe8ae2be3d 100644
--- a/crates/wizer/src/wasmtime.rs
+++ b/crates/wizer/src/wasmtime.rs
@@ -1,5 +1,5 @@
use crate::{InstanceState, SnapshotVal, Wizer};
-use anyhow::Context;
+use wasmtime::error::Context;
use wasmtime::{Extern, Instance, Module, Result, Store, Val};
impl Wizer {
@@ -10,7 +10,7 @@ impl Wizer {
store: &mut Store<T>,
wasm: &[u8],
instantiate: impl AsyncFnOnce(&mut Store<T>, &Module) -> Result<wasmtime::Instance>,
- ) -> anyhow::Result<Vec<u8>> {
+ ) -> wasmtime::Result<Vec<u8>> {
let (cx, instrumented_wasm) = self.instrument(wasm)?;
let engine = store.engine();
@@ -26,22 +26,22 @@ impl Wizer {
/// Check that the module exports an initialization function, and that the
/// function has the correct type.
- fn validate_init_func(&self, module: &wasmtime::Module) -> anyhow::Result<()> {
+ fn validate_init_func(&self, module: &wasmtime::Module) -> wasmtime::Result<()> {
log::debug!("Validating the exported initialization function");
match module.get_export(self.get_init_func()) {
Some(wasmtime::ExternType::Func(func_ty)) => {
if func_ty.params().len() != 0 || func_ty.results().len() != 0 {
- anyhow::bail!(
+ wasmtime::bail!(
"the Wasm module's `{}` function export does not have type `[] -> []`",
self.get_init_func()
);
}
}
- Some(_) => anyhow::bail!(
+ Some(_) => wasmtime::bail!(
"the Wasm module's `{}` export is not a function",
self.get_init_func()
),
- None => anyhow::bail!(
+ None => wasmtime::bail!(
"the Wasm module does not have a `{}` export",
self.get_init_func()
),
@@ -54,7 +54,7 @@ impl Wizer {
&self,
store: &mut Store<T>,
instance: &wasmtime::Instance,
- ) -> anyhow::Result<()> {
+ ) -> wasmtime::Result<()> {
log::debug!("Calling the initialization function");
if let Some(export) = instance.get_export(&mut *store, "_initialize") {
diff --git a/crates/wizer/tests/all/component.rs b/crates/wizer/tests/all/component.rs
index 8fe9b22f8d..3785b1fb40 100644
--- a/crates/wizer/tests/all/component.rs
+++ b/crates/wizer/tests/all/component.rs
@@ -1,6 +1,5 @@
-use anyhow::{Context, Result, bail};
use wasmtime::component::{Component, Instance, Linker, Val};
-use wasmtime::{Config, Engine, Store};
+use wasmtime::{Config, Engine, Result, Store, bail, error::Context as _};
use wasmtime_wizer::Wizer;
fn fail_wizening(msg: &str, wasm: &[u8]) -> Result<()> {
@@ -171,16 +170,16 @@ async fn wizen_and_run_wasm(expected: u32, wat: &str) -> Result<()> {
let instance = linker.instantiate_async(&mut store, &module).await?;
let run = instance.get_func(&mut store, "run").ok_or_else(|| {
- anyhow::anyhow!("the test Wasm component does not export a `run` function")
+ wasmtime::format_err!("the test Wasm component does not export a `run` function")
})?;
let mut actual = [Val::U8(0)];
run.call_async(&mut store, &[], &mut actual).await?;
let actual = match actual[0] {
Val::U32(x) => x,
- _ => anyhow::bail!("expected an u32 result"),
+ _ => wasmtime::bail!("expected an u32 result"),
};
- anyhow::ensure!(
+ wasmtime::ensure!(
expected == actual,
"expected `{expected}`, found `{actual}`",
);
diff --git a/crates/wizer/tests/all/make_linker.rs b/crates/wizer/tests/all/make_linker.rs
index 27685d21e3..65c5cc3ce0 100644
--- a/crates/wizer/tests/all/make_linker.rs
+++ b/crates/wizer/tests/all/make_linker.rs
@@ -1,4 +1,4 @@
-use anyhow::{Context, Result, anyhow};
+use wasmtime::{Result, error::Context as _, format_err};
use wasmtime_wasi::WasiCtxBuilder;
use wasmtime_wizer::Wizer;
use wat::parse_str as wat_to_wasm;
@@ -41,23 +41,23 @@ async fn run_wasm(args: &[wasmtime::Val], expected: i32, wasm: &[u8]) -> Result<
let mut linker = wasmtime::Linker::new(&engine);
linker.func_wrap("foo", "bar", |_: i32| -> Result<i32> {
- Err(anyhow!("shouldn't be called"))
+ Err(format_err!("shouldn't be called"))
})?;
let instance = linker.instantiate_async(&mut store, &module).await?;
- let run = instance
- .get_func(&mut store, "run")
- .ok_or_else(|| anyhow::anyhow!("the test Wasm module does not export a `run` function"))?;
+ let run = instance.get_func(&mut store, "run").ok_or_else(|| {
+ wasmtime::format_err!("the test Wasm module does not export a `run` function")
+ })?;
let mut actual = vec![wasmtime::Val::I32(0)];
run.call_async(&mut store, args, &mut actual).await?;
- anyhow::ensure!(actual.len() == 1, "expected one result");
+ wasmtime::ensure!(actual.len() == 1, "expected one result");
let actual = match actual[0] {
wasmtime::Val::I32(x) => x,
- _ => anyhow::bail!("expected an i32 result"),
+ _ => wasmtime::bail!("expected an i32 result"),
};
- anyhow::ensure!(
+ wasmtime::ensure!(
expected == actual,
"expected `{expected}`, found `{actual}`",
);
diff --git a/crates/wizer/tests/all/preloads.rs b/crates/wizer/tests/all/preloads.rs
index 0ddc2fcd8b..6e4a67a145 100644
--- a/crates/wizer/tests/all/preloads.rs
+++ b/crates/wizer/tests/all/preloads.rs
@@ -1,4 +1,4 @@
-use anyhow::Result;
+use wasmtime::Result;
use wasmtime::{Instance, Linker, Module};
use wasmtime_wizer::Wizer;
use wat::parse_str as wat_to_wasm;
@@ -50,7 +50,7 @@ async fn run_with_preloads(args: &[wasmtime::Val], wat: &str) -> Result<wasmtime
let inst = linker.instantiate_async(&mut store, &testmod).await?;
let run = inst
.get_func(&mut store, "run")
- .ok_or_else(|| anyhow::anyhow!("no `run` function on test module"))?;
+ .ok_or_else(|| wasmtime::format_err!("no `run` function on test module"))?;
let mut returned = vec![wasmtime::Val::I32(0)];
run.call_async(&mut store, args, &mut returned).await?;
Ok(returned[0])
diff --git a/crates/wizer/tests/all/tests.rs b/crates/wizer/tests/all/tests.rs
index 46fed8a0f3..c3e22b6d5d 100644
--- a/crates/wizer/tests/all/tests.rs
+++ b/crates/wizer/tests/all/tests.rs
@@ -1,7 +1,6 @@
-use anyhow::{Context, Result};
use std::process::Command;
use wasm_encoder::ConstExpr;
-use wasmtime::{Config, Engine, Instance, Linker, Module, Store};
+use wasmtime::{Config, Engine, Instance, Linker, Module, Result, Store, error::Context as _};
use wasmtime_wasi::{WasiCtxBuilder, p1};
use wasmtime_wizer::Wizer;
use wat::parse_str as wat_to_wasm;
@@ -73,18 +72,18 @@ async fn wizen_and_run_wasm(
let instance = linker.instantiate_async(&mut store, &module).await?;
- let run = instance
- .get_func(&mut store, "run")
- .ok_or_else(|| anyhow::anyhow!("the test Wasm module does not export a `run` function"))?;
+ let run = instance.get_func(&mut store, "run").ok_or_else(|| {
+ wasmtime::format_err!("the test Wasm module does not export a `run` function")
+ })?;
let mut actual = vec![wasmtime::Val::I32(0)];
run.call_async(&mut store, args, &mut actual).await?;
- anyhow::ensure!(actual.len() == 1, "expected one result");
+ wasmtime::ensure!(actual.len() == 1, "expected one result");
let actual = match actual[0] {
wasmtime::Val::I32(x) => x,
- _ => anyhow::bail!("expected an i32 result"),
+ _ => wasmtime::bail!("expected an i32 result"),
};
- anyhow::ensure!(
+ wasmtime::ensure!(
expected == actual,
"expected `{expected}`, found `{actual}`",
);
@@ -105,7 +104,7 @@ async fn fails_wizening(wat: &str) -> Result<()> {
.validate_all(&wasm)
.context("initial Wasm should be valid")?;
- anyhow::ensure!(
+ wasmtime::ensure!(
get_wizer()
.run(&mut store()?, &wasm, instantiate)
.await
@@ -319,7 +318,7 @@ async fn reject_table_get_set_with_reference_types_enabled() -> Result<()> {
}
#[tokio::test]
-async fn reject_table_grow_with_reference_types_enabled() -> anyhow::Result<()> {
+async fn reject_table_grow_with_reference_types_enabled() -> wasmtime::Result<()> {
let wat = r#"
(module
(elem declare func $f)
@@ -349,7 +348,7 @@ async fn reject_table_grow_with_reference_types_enabled() -> anyhow::Result<()>
}
#[tokio::test]
-async fn indirect_call_with_reference_types() -> anyhow::Result<()> {
+async fn indirect_call_with_reference_types() -> wasmtime::Result<()> {
let wat = r#"
(module
(type $sig (func (result i32)))
@@ -602,7 +601,7 @@ async fn rename_functions() -> Result<()> {
}
#[tokio::test]
-async fn wasi_reactor() -> anyhow::Result<()> {
+async fn wasi_reactor() -> wasmtime::Result<()> {
run_wat(
&[],
42,
@@ -628,7 +627,7 @@ async fn wasi_reactor() -> anyhow::Result<()> {
}
#[tokio::test]
-async fn wasi_reactor_initializer_as_init_func() -> anyhow::Result<()> {
+async fn wasi_reactor_initializer_as_init_func() -> wasmtime::Result<()> {
let wat = r#"
(module
(global $g (mut i32) i32.const 0)
@@ -652,7 +651,7 @@ async fn wasi_reactor_initializer_as_init_func() -> anyhow::Result<()> {
}
#[tokio::test]
-async fn wasi_reactor_initializer_with_keep_init() -> anyhow::Result<()> {
+async fn wasi_reactor_initializer_with_keep_init() -> wasmtime::Result<()> {
let wat = r#"
(module
(global $g (mut i32) i32.const 0)