Skip to content

Commit f237539

Browse files
authored
Migrate wast to wasmtime::error (#12264)
1 parent d634dff commit f237539

File tree

5 files changed

+15
-19
lines changed

5 files changed

+15
-19
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/wast/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ rust-version.workspace = true
1414
workspace = true
1515

1616
[dependencies]
17-
anyhow = { workspace = true }
1817
wasmtime = { workspace = true, features = ['cranelift', 'wat', 'runtime', 'gc', 'async', 'threads'] }
1918
wast = { workspace = true, features = ['dwarf'] }
2019
log = { workspace = true }

crates/wast/src/component.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::core;
2-
use anyhow::{Context, Result, bail};
32
use json_from_wast::{ComponentConst, FloatConst};
43
use std::collections::BTreeSet;
54
use std::fmt::Debug;
5+
use wasmtime::{Result, bail, error::Context as _};
66

77
pub use wasmtime::component::*;
88

crates/wast/src/core.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use crate::WastContext;
2-
use anyhow::{Context, Result, anyhow, bail};
32
use json_from_wast::{CoreConst, FloatConst, V128};
43
use std::fmt::{Display, LowerHex};
5-
use wasmtime::{Store, Val};
4+
use wasmtime::{Result, Store, Val, bail, error::Context as _, format_err};
65

76
/// Translate from a `script::Value` to a `RuntimeValue`.
87
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
139138
let x = x
140139
.data(store)?
141140
.ok_or_else(|| {
142-
anyhow!("expected an externref of a u32, found externref without host data")
141+
format_err!("expected an externref of a u32, found externref without host data")
143142
})?
144143
.downcast_ref::<u32>()
145144
.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
188187
let x = x
189188
.data(&mut *store)?
190189
.ok_or_else(|| {
191-
anyhow!(
190+
format_err!(
192191
"expected anyref of externref of u32, found anyref that is \
193192
not a converted externref"
194193
)

crates/wast/src/wast.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
use crate::component;
33
use crate::core;
44
use crate::spectest::*;
5-
use anyhow::{Context as _, anyhow, bail};
65
use json_from_wast::{Action, Command, Const, WasmFile, WasmFileType};
76
use std::collections::HashMap;
87
use std::path::{Path, PathBuf};
98
use std::str;
109
use std::sync::Arc;
1110
use std::thread;
12-
use wasmtime::*;
11+
use wasmtime::{error::Context as _, *};
1312
use wast::lexer::Lexer;
1413
use wast::parser::{self, ParseBuffer};
1514

@@ -172,24 +171,24 @@ impl WastContext {
172171
return Ok(Export::Core(
173172
self.core_linker
174173
.get(&mut self.core_store, module, name)
175-
.ok_or_else(|| anyhow!("no item named `{module}::{name}` found"))?,
174+
.ok_or_else(|| format_err!("no item named `{module}::{name}` found"))?,
176175
));
177176
}
178177

179178
let cur = self
180179
.current
181180
.as_mut()
182-
.ok_or_else(|| anyhow!("no previous instance found"))?;
181+
.ok_or_else(|| format_err!("no previous instance found"))?;
183182
Ok(match cur {
184183
InstanceKind::Core(i) => Export::Core(
185184
i.get_export(&mut self.core_store, name)
186-
.ok_or_else(|| anyhow!("no item named `{name}` found"))?,
185+
.ok_or_else(|| format_err!("no item named `{name}` found"))?,
187186
),
188187
#[cfg(feature = "component-model")]
189188
InstanceKind::Component(store, i) => {
190189
let export = i
191190
.get_func(&mut *store, name)
192-
.ok_or_else(|| anyhow!("no func named `{name}` found"))?;
191+
.ok_or_else(|| format_err!("no func named `{name}` found"))?;
193192
Export::Component(store, export)
194193
}
195194
})
@@ -267,7 +266,7 @@ impl WastContext {
267266
drop(replace);
268267
let func = export
269268
.into_func()
270-
.ok_or_else(|| anyhow!("no function named `{field}`"))?;
269+
.ok_or_else(|| format_err!("no function named `{field}`"))?;
271270
let values = args
272271
.iter()
273272
.map(|v| match v {
@@ -390,7 +389,7 @@ impl WastContext {
390389
WasmFileType::Text => file
391390
.binary_filename
392391
.as_ref()
393-
.ok_or_else(|| anyhow!("cannot compile module that isn't a valid binary"))?,
392+
.ok_or_else(|| format_err!("cannot compile module that isn't a valid binary"))?,
394393
WasmFileType::Binary => &file.filename,
395394
};
396395

@@ -445,7 +444,7 @@ impl WastContext {
445444
let current = self
446445
.current
447446
.as_ref()
448-
.ok_or(anyhow!("no previous instance"))?;
447+
.ok_or(format_err!("no previous instance"))?;
449448
match current {
450449
InstanceKind::Core(current) => {
451450
self.core_linker
@@ -466,7 +465,7 @@ impl WastContext {
466465
let global = match self.get_export(instance_name, field)? {
467466
Export::Core(e) => e
468467
.into_global()
469-
.ok_or_else(|| anyhow!("no global named `{field}`"))?,
468+
.ok_or_else(|| format_err!("no global named `{field}`"))?,
470469
#[cfg(feature = "component-model")]
471470
Export::Component(..) => bail!("no global named `{field}`"),
472471
};
@@ -651,7 +650,7 @@ impl WastContext {
651650
.as_deref()
652651
.and_then(|n| self.modules.get(n))
653652
.cloned()
654-
.ok_or_else(|| anyhow!("no module named {module:?}"))?;
653+
.ok_or_else(|| format_err!("no module named {module:?}"))?;
655654
self.module(instance.as_deref(), &module)?;
656655
}
657656
Register { line: _, name, as_ } => {
@@ -788,7 +787,7 @@ impl WastContext {
788787
Wait { thread, .. } => {
789788
threads
790789
.remove(&thread[..])
791-
.ok_or_else(|| anyhow!("no thread named `{thread}`"))?
790+
.ok_or_else(|| format_err!("no thread named `{thread}`"))?
792791
.join()
793792
.unwrap()?;
794793
}

0 commit comments

Comments
 (0)