Skip to content

Commit c8ae642

Browse files
committed
Do not re-export anyhow! in the wasmtime::prelude
We are trying to move to `format_err!` instead.
1 parent 69e81cb commit c8ae642

File tree

25 files changed

+38
-36
lines changed

25 files changed

+38
-36
lines changed

crates/wasmtime/src/compile/code_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl<'a> CodeBuilder<'a> {
204204
let wasm = self
205205
.wasm
206206
.as_deref()
207-
.ok_or_else(|| anyhow!("no wasm bytes have been configured"))?;
207+
.ok_or_else(|| format_err!("no wasm bytes have been configured"))?;
208208

209209
#[cfg(not(feature = "compile-time-builtins"))]
210210
{

crates/wasmtime/src/compile/code_builder/compile_time_builtins.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ impl<'a> CodeBuilder<'a> {
6161
main_wasm: &'b [u8],
6262
) -> Result<crate::hash_set::HashSet<&'b str>, Error> {
6363
let intrinsics_import = self.unsafe_intrinsics_import.as_deref().ok_or_else(|| {
64-
anyhow!("must configure the unsafe-intrinsics import when using compile-time builtins")
64+
format_err!(
65+
"must configure the unsafe-intrinsics import when using compile-time builtins"
66+
)
6567
})?;
6668

6769
let mut instance_imports = crate::hash_set::HashSet::new();

crates/wasmtime/src/engine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ impl Engine {
637637

638638
pub(crate) fn try_compiler(&self) -> Result<&dyn wasmtime_environ::Compiler> {
639639
self.compiler()
640-
.ok_or_else(|| anyhow!("Engine was not configured with a compiler"))
640+
.ok_or_else(|| format_err!("Engine was not configured with a compiler"))
641641
}
642642

643643
/// Ahead-of-time (AOT) compiles a WebAssembly module.

crates/wasmtime/src/engine/serialization.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,18 @@ pub fn check_compatible(engine: &Engine, mmap: &[u8], expected: ObjectKind) -> R
7575

7676
let data = obj
7777
.section_by_name(obj::ELF_WASM_ENGINE)
78-
.ok_or_else(|| anyhow!("failed to find section `{}`", obj::ELF_WASM_ENGINE))?
78+
.ok_or_else(|| format_err!("failed to find section `{}`", obj::ELF_WASM_ENGINE))?
7979
.data()
8080
.map_err(obj::ObjectCrateErrorWrapper)?;
8181
let (first, data) = data
8282
.split_first()
83-
.ok_or_else(|| anyhow!("invalid engine section"))?;
83+
.ok_or_else(|| format_err!("invalid engine section"))?;
8484
if *first != VERSION {
8585
bail!("mismatched version in engine section");
8686
}
8787
let (len, data) = data
8888
.split_first()
89-
.ok_or_else(|| anyhow!("invalid engine section"))?;
89+
.ok_or_else(|| format_err!("invalid engine section"))?;
9090
let len = usize::from(*len);
9191
let (version, data) = if data.len() < len + 1 {
9292
bail!("engine section too small")
@@ -202,7 +202,7 @@ impl Metadata<'_> {
202202
fn check_triple(&self, engine: &Engine) -> Result<()> {
203203
let engine_target = engine.target();
204204
let module_target =
205-
target_lexicon::Triple::from_str(&self.target).map_err(|e| anyhow!(e))?;
205+
target_lexicon::Triple::from_str(&self.target).map_err(|e| format_err!(e))?;
206206

207207
if module_target.architecture != engine_target.architecture {
208208
bail!(

crates/wasmtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ extern crate std;
310310
extern crate alloc;
311311

312312
pub(crate) mod prelude {
313-
pub use crate::error::{Context, Error, Result, anyhow, bail, ensure, format_err};
313+
pub use crate::error::{Context, Error, Result, bail, ensure, format_err};
314314
pub use wasmtime_environ::prelude::*;
315315
}
316316

crates/wasmtime/src/runtime/code_memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl CodeMemory {
214214
published: false,
215215
registered: false,
216216
enable_branch_protection: enable_branch_protection
217-
.ok_or_else(|| anyhow!("missing `{}` section", obj::ELF_WASM_BTI))?,
217+
.ok_or_else(|| format_err!("missing `{}` section", obj::ELF_WASM_BTI))?,
218218
needs_executable,
219219
#[cfg(feature = "debug-builtins")]
220220
has_native_debug_info,

crates/wasmtime/src/runtime/component/func/host.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ where
292292
// Exiting the component is disallowed, for example, when the `realloc`
293293
// function calls a canonical import.
294294
if unsafe { !flags.may_leave() } {
295-
return Err(anyhow!(crate::Trap::CannotLeaveComponent));
295+
return Err(format_err!(crate::Trap::CannotLeaveComponent));
296296
}
297297

298298
if opts.async_ {

crates/wasmtime/src/runtime/component/func/typed.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,7 @@ fn lower_string<T>(cx: &mut LowerContext<'_, T>, string: &str) -> Result<(usize,
15491549
let worst_case = bytes
15501550
.len()
15511551
.checked_mul(2)
1552-
.ok_or_else(|| anyhow!("byte length overflow"))?;
1552+
.ok_or_else(|| format_err!("byte length overflow"))?;
15531553
if worst_case > MAX_STRING_BYTE_LENGTH {
15541554
bail!("byte length too large");
15551555
}
@@ -1853,7 +1853,7 @@ where
18531853
let size = list
18541854
.len()
18551855
.checked_mul(elem_size)
1856-
.ok_or_else(|| anyhow!("size overflow copying a list"))?;
1856+
.ok_or_else(|| format_err!("size overflow copying a list"))?;
18571857
let ptr = cx.realloc(0, 0, T::ALIGN32, size)?;
18581858
T::linear_store_list_to_memory(cx, ty, ptr, list)?;
18591859
Ok((ptr, list.len()))

crates/wasmtime/src/runtime/component/instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl Instance {
197197
{
198198
let f = self
199199
.get_func(store.as_context_mut(), name)
200-
.ok_or_else(|| anyhow!("failed to find function export"))?;
200+
.ok_or_else(|| format_err!("failed to find function export"))?;
201201
Ok(f.typed::<Params, Results>(store)
202202
.with_context(|| format!("failed to convert function to given type"))?)
203203
}

crates/wasmtime/src/runtime/component/matching.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl TypeChecker<'_> {
121121
let idx = actual
122122
.exports
123123
.get(name)
124-
.ok_or_else(|| anyhow!("module export `{name}` not defined"))?;
124+
.ok_or_else(|| format_err!("module export `{name}` not defined"))?;
125125
let actual = actual.type_of(*idx);
126126
matching::entity_ty(self.engine, expected, &actual)
127127
.with_context(|| format!("module export `{name}` has the wrong type"))?;
@@ -136,7 +136,7 @@ impl TypeChecker<'_> {
136136
let expected = expected
137137
.imports
138138
.get(&(module.to_string(), name.to_string()))
139-
.ok_or_else(|| anyhow!("module import `{module}::{name}` not defined"))?;
139+
.ok_or_else(|| format_err!("module import `{module}::{name}` not defined"))?;
140140
matching::entity_ty(self.engine, &actual, expected)
141141
.with_context(|| format!("module import `{module}::{name}` has the wrong type"))?;
142142
}

0 commit comments

Comments
 (0)