Skip to content

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

Migrate wast to `wasmtime::error` (#12264)

Nick Fitzgeraldf23753932c29
diff --git a/Cargo.lock b/Cargo.lock
index abca974c09..4149b9566f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5234,7 +5234,6 @@ dependencies = [
name = "wasmtime-wast"
version = "42.0.0"
dependencies = [
- "anyhow",
"json-from-wast",
"log",
"object 0.37.3",
diff --git a/crates/wast/Cargo.toml b/crates/wast/Cargo.toml
index 7d30b2069a..aa646bcab9 100644
--- a/crates/wast/Cargo.toml
+++ b/crates/wast/Cargo.toml
@@ -14,7 +14,6 @@ rust-version.workspace = true
workspace = true
[dependencies]
-anyhow = { workspace = true }
wasmtime = { workspace = true, features = ['cranelift', 'wat', 'runtime', 'gc', 'async', 'threads'] }
wast = { workspace = true, features = ['dwarf'] }
log = { workspace = true }
diff --git a/crates/wast/src/component.rs b/crates/wast/src/component.rs
index c2fcc932f8..1de0bb1ba3 100644
--- a/crates/wast/src/component.rs
+++ b/crates/wast/src/component.rs
@@ -1,8 +1,8 @@
use crate::core;
-use anyhow::{Context, Result, bail};
use json_from_wast::{ComponentConst, FloatConst};
use std::collections::BTreeSet;
use std::fmt::Debug;
+use wasmtime::{Result, bail, error::Context as _};
pub use wasmtime::component::*;
diff --git a/crates/wast/src/core.rs b/crates/wast/src/core.rs
index 5fa06ad43a..3f3b8453d9 100644
--- a/crates/wast/src/core.rs
+++ b/crates/wast/src/core.rs
@@ -1,8 +1,7 @@
use crate::WastContext;
-use anyhow::{Context, Result, anyhow, bail};
use json_from_wast::{CoreConst, FloatConst, V128};
use std::fmt::{Display, LowerHex};
-use wasmtime::{Store, Val};
+use wasmtime::{Result, Store, Val, bail, error::Context as _, format_err};
/// Translate from a `script::Value` to a `RuntimeValue`.
pub fn val(ctx: &mut WastContext, v: &CoreConst) -> Result<Val> {
@@ -139,7 +138,7 @@ pub fn match_val(store: &mut Store<()>, actual: &Val, expected: &CoreConst) -> R
let x = x
.data(store)?
.ok_or_else(|| {
- anyhow!("expected an externref of a u32, found externref without host data")
+ format_err!("expected an externref of a u32, found externref without host data")
})?
.downcast_ref::<u32>()
.expect("only u32 externrefs created in wast test suites");
@@ -188,7 +187,7 @@ pub fn match_val(store: &mut Store<()>, actual: &Val, expected: &CoreConst) -> R
let x = x
.data(&mut *store)?
.ok_or_else(|| {
- anyhow!(
+ format_err!(
"expected anyref of externref of u32, found anyref that is \
not a converted externref"
)
diff --git a/crates/wast/src/wast.rs b/crates/wast/src/wast.rs
index 97e0b84be3..b656294e23 100644
--- a/crates/wast/src/wast.rs
+++ b/crates/wast/src/wast.rs
@@ -2,14 +2,13 @@
use crate::component;
use crate::core;
use crate::spectest::*;
-use anyhow::{Context as _, anyhow, bail};
use json_from_wast::{Action, Command, Const, WasmFile, WasmFileType};
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::str;
use std::sync::Arc;
use std::thread;
-use wasmtime::*;
+use wasmtime::{error::Context as _, *};
use wast::lexer::Lexer;
use wast::parser::{self, ParseBuffer};
@@ -172,24 +171,24 @@ impl WastContext {
return Ok(Export::Core(
self.core_linker
.get(&mut self.core_store, module, name)
- .ok_or_else(|| anyhow!("no item named `{module}::{name}` found"))?,
+ .ok_or_else(|| format_err!("no item named `{module}::{name}` found"))?,
));
}
let cur = self
.current
.as_mut()
- .ok_or_else(|| anyhow!("no previous instance found"))?;
+ .ok_or_else(|| format_err!("no previous instance found"))?;
Ok(match cur {
InstanceKind::Core(i) => Export::Core(
i.get_export(&mut self.core_store, name)
- .ok_or_else(|| anyhow!("no item named `{name}` found"))?,
+ .ok_or_else(|| format_err!("no item named `{name}` found"))?,
),
#[cfg(feature = "component-model")]
InstanceKind::Component(store, i) => {
let export = i
.get_func(&mut *store, name)
- .ok_or_else(|| anyhow!("no func named `{name}` found"))?;
+ .ok_or_else(|| format_err!("no func named `{name}` found"))?;
Export::Component(store, export)
}
})
@@ -267,7 +266,7 @@ impl WastContext {
drop(replace);
let func = export
.into_func()
- .ok_or_else(|| anyhow!("no function named `{field}`"))?;
+ .ok_or_else(|| format_err!("no function named `{field}`"))?;
let values = args
.iter()
.map(|v| match v {
@@ -390,7 +389,7 @@ impl WastContext {
WasmFileType::Text => file
.binary_filename
.as_ref()
- .ok_or_else(|| anyhow!("cannot compile module that isn't a valid binary"))?,
+ .ok_or_else(|| format_err!("cannot compile module that isn't a valid binary"))?,
WasmFileType::Binary => &file.filename,
};
@@ -445,7 +444,7 @@ impl WastContext {
let current = self
.current
.as_ref()
- .ok_or(anyhow!("no previous instance"))?;
+ .ok_or(format_err!("no previous instance"))?;
match current {
InstanceKind::Core(current) => {
self.core_linker
@@ -466,7 +465,7 @@ impl WastContext {
let global = match self.get_export(instance_name, field)? {
Export::Core(e) => e
.into_global()
- .ok_or_else(|| anyhow!("no global named `{field}`"))?,
+ .ok_or_else(|| format_err!("no global named `{field}`"))?,
#[cfg(feature = "component-model")]
Export::Component(..) => bail!("no global named `{field}`"),
};
@@ -651,7 +650,7 @@ impl WastContext {
.as_deref()
.and_then(|n| self.modules.get(n))
.cloned()
- .ok_or_else(|| anyhow!("no module named {module:?}"))?;
+ .ok_or_else(|| format_err!("no module named {module:?}"))?;
self.module(instance.as_deref(), &module)?;
}
Register { line: _, name, as_ } => {
@@ -788,7 +787,7 @@ impl WastContext {
Wait { thread, .. } => {
threads
.remove(&thread[..])
- .ok_or_else(|| anyhow!("no thread named `{thread}`"))?
+ .ok_or_else(|| format_err!("no thread named `{thread}`"))?
.join()
.unwrap()?;
}