A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Do not re-export `anyhow!` in the `wasmtime::prelude` (#12298)
Nick Fitzgeraldff33e949632c
diff --git a/crates/wasmtime/src/compile/code_builder.rs b/crates/wasmtime/src/compile/code_builder.rsindex 029cbe1803..5fc10bbf09 100644--- a/crates/wasmtime/src/compile/code_builder.rs+++ b/crates/wasmtime/src/compile/code_builder.rs@@ -204,7 +204,7 @@ impl<'a> CodeBuilder<'a> {let wasm = self.wasm.as_deref()- .ok_or_else(|| anyhow!("no wasm bytes have been configured"))?;+ .ok_or_else(|| format_err!("no wasm bytes have been configured"))?;#[cfg(not(feature = "compile-time-builtins"))]{diff --git a/crates/wasmtime/src/compile/code_builder/compile_time_builtins.rs b/crates/wasmtime/src/compile/code_builder/compile_time_builtins.rsindex dc62fe8a5c..5b3ae65538 100644--- a/crates/wasmtime/src/compile/code_builder/compile_time_builtins.rs+++ b/crates/wasmtime/src/compile/code_builder/compile_time_builtins.rs@@ -61,7 +61,9 @@ impl<'a> CodeBuilder<'a> {main_wasm: &'b [u8],) -> Result<crate::hash_set::HashSet<&'b str>, Error> {let intrinsics_import = self.unsafe_intrinsics_import.as_deref().ok_or_else(|| {- anyhow!("must configure the unsafe-intrinsics import when using compile-time builtins")+ format_err!(+ "must configure the unsafe-intrinsics import when using compile-time builtins"+ )})?;let mut instance_imports = crate::hash_set::HashSet::new();diff --git a/crates/wasmtime/src/engine.rs b/crates/wasmtime/src/engine.rsindex a2092dabf9..04ce15903d 100644--- a/crates/wasmtime/src/engine.rs+++ b/crates/wasmtime/src/engine.rs@@ -637,7 +637,7 @@ impl Engine {pub(crate) fn try_compiler(&self) -> Result<&dyn wasmtime_environ::Compiler> {self.compiler()- .ok_or_else(|| anyhow!("Engine was not configured with a compiler"))+ .ok_or_else(|| format_err!("Engine was not configured with a compiler"))}/// Ahead-of-time (AOT) compiles a WebAssembly module.diff --git a/crates/wasmtime/src/engine/serialization.rs b/crates/wasmtime/src/engine/serialization.rsindex 8d5d4cd9ac..aeb962d853 100644--- a/crates/wasmtime/src/engine/serialization.rs+++ b/crates/wasmtime/src/engine/serialization.rs@@ -75,18 +75,18 @@ pub fn check_compatible(engine: &Engine, mmap: &[u8], expected: ObjectKind) -> Rlet data = obj.section_by_name(obj::ELF_WASM_ENGINE)- .ok_or_else(|| anyhow!("failed to find section `{}`", obj::ELF_WASM_ENGINE))?+ .ok_or_else(|| format_err!("failed to find section `{}`", obj::ELF_WASM_ENGINE))?.data().map_err(obj::ObjectCrateErrorWrapper)?;let (first, data) = data.split_first()- .ok_or_else(|| anyhow!("invalid engine section"))?;+ .ok_or_else(|| format_err!("invalid engine section"))?;if *first != VERSION {bail!("mismatched version in engine section");}let (len, data) = data.split_first()- .ok_or_else(|| anyhow!("invalid engine section"))?;+ .ok_or_else(|| format_err!("invalid engine section"))?;let len = usize::from(*len);let (version, data) = if data.len() < len + 1 {bail!("engine section too small")@@ -202,7 +202,7 @@ impl Metadata<'_> {fn check_triple(&self, engine: &Engine) -> Result<()> {let engine_target = engine.target();let module_target =- target_lexicon::Triple::from_str(&self.target).map_err(|e| anyhow!(e))?;+ target_lexicon::Triple::from_str(&self.target).map_err(|e| format_err!(e))?;if module_target.architecture != engine_target.architecture {bail!(diff --git a/crates/wasmtime/src/lib.rs b/crates/wasmtime/src/lib.rsindex f5bf0f8b1e..1f6d0b206c 100644--- a/crates/wasmtime/src/lib.rs+++ b/crates/wasmtime/src/lib.rs@@ -310,7 +310,7 @@ extern crate std;extern crate alloc;pub(crate) mod prelude {- pub use crate::error::{Context, Error, Result, anyhow, bail, ensure, format_err};+ pub use crate::error::{Context, Error, Result, bail, ensure, format_err};pub use wasmtime_environ::prelude::*;}diff --git a/crates/wasmtime/src/runtime/code_memory.rs b/crates/wasmtime/src/runtime/code_memory.rsindex bfb24a68e3..a66029cec4 100644--- a/crates/wasmtime/src/runtime/code_memory.rs+++ b/crates/wasmtime/src/runtime/code_memory.rs@@ -214,7 +214,7 @@ impl CodeMemory {published: false,registered: false,enable_branch_protection: enable_branch_protection- .ok_or_else(|| anyhow!("missing `{}` section", obj::ELF_WASM_BTI))?,+ .ok_or_else(|| format_err!("missing `{}` section", obj::ELF_WASM_BTI))?,needs_executable,#[cfg(feature = "debug-builtins")]has_native_debug_info,diff --git a/crates/wasmtime/src/runtime/component/func/host.rs b/crates/wasmtime/src/runtime/component/func/host.rsindex a20a80d23e..9c27afef8b 100644--- a/crates/wasmtime/src/runtime/component/func/host.rs+++ b/crates/wasmtime/src/runtime/component/func/host.rs@@ -293,7 +293,7 @@ where// Exiting the component is disallowed, for example, when the `realloc`// function calls a canonical import.if unsafe { !flags.may_leave() } {- return Err(anyhow!(crate::Trap::CannotLeaveComponent));+ return Err(format_err!(crate::Trap::CannotLeaveComponent));}if opts.async_ {diff --git a/crates/wasmtime/src/runtime/component/func/typed.rs b/crates/wasmtime/src/runtime/component/func/typed.rsindex ee3a46c187..add17eddea 100644--- a/crates/wasmtime/src/runtime/component/func/typed.rs+++ b/crates/wasmtime/src/runtime/component/func/typed.rs@@ -1549,7 +1549,7 @@ fn lower_string<T>(cx: &mut LowerContext<'_, T>, string: &str) -> Result<(usize,let worst_case = bytes.len().checked_mul(2)- .ok_or_else(|| anyhow!("byte length overflow"))?;+ .ok_or_else(|| format_err!("byte length overflow"))?;if worst_case > MAX_STRING_BYTE_LENGTH {bail!("byte length too large");}@@ -1853,7 +1853,7 @@ wherelet size = list.len().checked_mul(elem_size)- .ok_or_else(|| anyhow!("size overflow copying a list"))?;+ .ok_or_else(|| format_err!("size overflow copying a list"))?;let ptr = cx.realloc(0, 0, T::ALIGN32, size)?;T::linear_store_list_to_memory(cx, ty, ptr, list)?;Ok((ptr, list.len()))diff --git a/crates/wasmtime/src/runtime/component/instance.rs b/crates/wasmtime/src/runtime/component/instance.rsindex 41c7f6cd8d..22934f84db 100644--- a/crates/wasmtime/src/runtime/component/instance.rs+++ b/crates/wasmtime/src/runtime/component/instance.rs@@ -197,7 +197,7 @@ impl Instance {{let f = self.get_func(store.as_context_mut(), name)- .ok_or_else(|| anyhow!("failed to find function export"))?;+ .ok_or_else(|| format_err!("failed to find function export"))?;Ok(f.typed::<Params, Results>(store).with_context(|| format!("failed to convert function to given type"))?)}diff --git a/crates/wasmtime/src/runtime/component/matching.rs b/crates/wasmtime/src/runtime/component/matching.rsindex 8e893958bc..b972d1b91b 100644--- a/crates/wasmtime/src/runtime/component/matching.rs+++ b/crates/wasmtime/src/runtime/component/matching.rs@@ -121,7 +121,7 @@ impl TypeChecker<'_> {let idx = actual.exports.get(name)- .ok_or_else(|| anyhow!("module export `{name}` not defined"))?;+ .ok_or_else(|| format_err!("module export `{name}` not defined"))?;let actual = actual.type_of(*idx);matching::entity_ty(self.engine, expected, &actual).with_context(|| format!("module export `{name}` has the wrong type"))?;@@ -136,7 +136,7 @@ impl TypeChecker<'_> {let expected = expected.imports.get(&(module.to_string(), name.to_string()))- .ok_or_else(|| anyhow!("module import `{module}::{name}` not defined"))?;+ .ok_or_else(|| format_err!("module import `{module}::{name}` not defined"))?;matching::entity_ty(self.engine, &actual, expected).with_context(|| format!("module import `{module}::{name}` has the wrong type"))?;}diff --git a/crates/wasmtime/src/runtime/component/values.rs b/crates/wasmtime/src/runtime/component/values.rsindex 43a4335c12..d0b1d0209d 100644--- a/crates/wasmtime/src/runtime/component/values.rs+++ b/crates/wasmtime/src/runtime/component/values.rs@@ -957,7 +957,7 @@ fn load_variant(}};let case_ty = types.nth(discriminant as usize).ok_or_else(|| {- anyhow!(+ format_err!("discriminant {} out of range [0..{})",discriminant,types.len()@@ -989,7 +989,7 @@ fn lift_variant(let discriminant = next(src).get_u32();let ty = types.nth(discriminant as usize)- .ok_or_else(|| anyhow!("discriminant {discriminant} out of range [0..{len})"))?;+ .ok_or_else(|| format_err!("discriminant {discriminant} out of range [0..{len})"))?;let (value, value_flat) = match ty {Some(ty) => (Some(Box::new(Val::lift(cx, ty, src)?)),diff --git a/crates/wasmtime/src/runtime/gc/enabled/rooting.rs b/crates/wasmtime/src/runtime/gc/enabled/rooting.rsindex 7e06c85d4d..02f3c2757f 100644--- a/crates/wasmtime/src/runtime/gc/enabled/rooting.rs+++ b/crates/wasmtime/src/runtime/gc/enabled/rooting.rs@@ -214,7 +214,7 @@ mod sealed {/// objects that have been unrooted.fn try_gc_ref<'a>(&self, store: &'a StoreOpaque) -> Result<&'a VMGcRef> {self.get_gc_ref(store).ok_or_else(|| {- anyhow!("attempted to use a garbage-collected object that has been unrooted")+ format_err!("attempted to use a garbage-collected object that has been unrooted")})}@@ -314,7 +314,7 @@ impl GcRootIndex {/// Panics if `self` is not associated with the given store.pub(crate) fn try_gc_ref<'a>(&self, store: &'a StoreOpaque) -> Result<&'a VMGcRef> {self.get_gc_ref(store).ok_or_else(|| {- anyhow!("attempted to use a garbage-collected object that has been unrooted")+ format_err!("attempted to use a garbage-collected object that has been unrooted")})}diff --git a/crates/wasmtime/src/runtime/instance.rs b/crates/wasmtime/src/runtime/instance.rsindex f46b683201..e4e496e0e9 100644--- a/crates/wasmtime/src/runtime/instance.rs+++ b/crates/wasmtime/src/runtime/instance.rs@@ -525,7 +525,7 @@ impl Instance {let f = self.get_export(store.as_context_mut(), name).and_then(|f| f.into_func())- .ok_or_else(|| anyhow!("failed to find function export `{name}`"))?;+ .ok_or_else(|| format_err!("failed to find function export `{name}`"))?;Ok(f.typed::<Params, Results>(store).with_context(|| format!("failed to convert function `{name}` to given type"))?)}diff --git a/crates/wasmtime/src/runtime/linker.rs b/crates/wasmtime/src/runtime/linker.rsindex a04a4b6dbc..9d399cff41 100644--- a/crates/wasmtime/src/runtime/linker.rs+++ b/crates/wasmtime/src/runtime/linker.rs@@ -290,7 +290,7 @@ impl<T> Linker<T> {if let Err(import_err) = self._get_by_import(&import) {let default_extern =import_err.ty().default_value(&mut store).with_context(|| {- anyhow!(+ format_err!("no default value exists for `{}::{}` with type `{:?}`",import.module(),import.name(),diff --git a/crates/wasmtime/src/runtime/native_debug.rs b/crates/wasmtime/src/runtime/native_debug.rsindex ffaf3e90e3..e241b66178 100644--- a/crates/wasmtime/src/runtime/native_debug.rs+++ b/crates/wasmtime/src/runtime/native_debug.rs@@ -68,7 +68,7 @@ fn relocate_dwarf_sections(bytes: &mut [u8], code_region: (*const u8, usize)) ->.try_into().ok().and_then(|offset| object::from_bytes_mut::<U64Bytes<NE>>(&mut bytes[offset..]).ok())- .ok_or_else(|| anyhow!("invalid dwarf relocations"))?;+ .ok_or_else(|| format_err!("invalid dwarf relocations"))?;loc.set(NE, value);}Ok(())diff --git a/crates/wasmtime/src/runtime/store/gc.rs b/crates/wasmtime/src/runtime/store/gc.rsindex 70f60f444f..6232030bd1 100644--- a/crates/wasmtime/src/runtime/store/gc.rs+++ b/crates/wasmtime/src/runtime/store/gc.rs@@ -113,7 +113,7 @@ impl StoreOpaque {heap.memory.grow(delta_pages_for_alloc, limiter).await?- .ok_or_else(|| anyhow!("failed to grow GC heap"))?;+ .ok_or_else(|| format_err!("failed to grow GC heap"))?;}heap.store.vm_store_context.gc_heap = heap.memory.vmmemory();diff --git a/crates/wasmtime/src/runtime/trampoline/memory.rs b/crates/wasmtime/src/runtime/trampoline/memory.rsindex e9a1c5ca2c..21854b314f 100644--- a/crates/wasmtime/src/runtime/trampoline/memory.rs+++ b/crates/wasmtime/src/runtime/trampoline/memory.rs@@ -115,7 +115,7 @@ impl RuntimeMemoryCreator for MemoryCreatorProxy {usize::try_from(tunables.memory_guard_size).unwrap(),).map(|mem| Box::new(LinearMemoryProxy { mem }) as Box<dyn RuntimeLinearMemory>)- .map_err(|e| anyhow!(e))+ .map_err(|e| format_err!(e))}}diff --git a/crates/wasmtime/src/runtime/types.rs b/crates/wasmtime/src/runtime/types.rsindex 4a67e6668f..400a314b7a 100644--- a/crates/wasmtime/src/runtime/types.rs+++ b/crates/wasmtime/src/runtime/types.rs@@ -2705,7 +2705,7 @@ impl FuncType {.results().map(|ty| ty.default_value()).collect::<Option<Vec<_>>>()- .ok_or_else(|| anyhow!("function results do not have a default value"))?;+ .ok_or_else(|| format_err!("function results do not have a default value"))?;Ok(Func::new(&mut store, self.clone(), move |_, _, results| {for (slot, dummy) in results.iter_mut().zip(dummy_results.iter()) {*slot = *dummy;@@ -3000,7 +3000,7 @@ impl GlobalType {let val = self.content().default_value()- .ok_or_else(|| anyhow!("global type has no default value"))?;+ .ok_or_else(|| format_err!("global type has no default value"))?;RuntimeGlobal::new(store, self.clone(), val)}diff --git a/crates/wasmtime/src/runtime/types/matching.rs b/crates/wasmtime/src/runtime/types/matching.rsindex 49ffc3c67f..f0158fb837 100644--- a/crates/wasmtime/src/runtime/types/matching.rs+++ b/crates/wasmtime/src/runtime/types/matching.rs@@ -101,7 +101,7 @@ pub fn entity_ty(engine: &Engine, expected: &EntityType, actual: &EntityType) ->}fn concrete_type_mismatch(msg: &str, expected: &WasmSubType, actual: &WasmSubType) -> crate::Error {- anyhow!("{msg}: expected type `{expected}`, found type `{actual}`")+ format_err!("{msg}: expected type `{expected}`, found type `{actual}`")}fn global_ty(engine: &Engine, expected: &Global, actual: &Global) -> Result<()> {diff --git a/crates/wasmtime/src/runtime/vm/component/libcalls.rs b/crates/wasmtime/src/runtime/vm/component/libcalls.rsindex 01c6f45897..ae3d18edb6 100644--- a/crates/wasmtime/src/runtime/vm/component/libcalls.rs+++ b/crates/wasmtime/src/runtime/vm/component/libcalls.rs@@ -192,7 +192,7 @@ unsafe fn utf8_to_utf8(let dst = unsafe { slice::from_raw_parts_mut(dst, len) };assert_no_overlap(src, dst);log::trace!("utf8-to-utf8 {len}");- let src = core::str::from_utf8(src).map_err(|_| anyhow!("invalid utf8 encoding"))?;+ let src = core::str::from_utf8(src).map_err(|_| format_err!("invalid utf8 encoding"))?;dst.copy_from_slice(src.as_bytes());Ok(())}@@ -222,7 +222,7 @@ unsafe fn utf16_to_utf16(fn run_utf16_to_utf16(src: &[u16], mut dst: &mut [u16]) -> Result<bool> {let mut all_latin1 = true;for ch in core::char::decode_utf16(src.iter().map(|i| u16::from_le(*i))) {- let ch = ch.map_err(|_| anyhow!("invalid utf16 encoding"))?;+ let ch = ch.map_err(|_| format_err!("invalid utf16 encoding"))?;all_latin1 = all_latin1 && u8::try_from(u32::from(ch)).is_ok();let result = ch.encode_utf16(dst);let size = result.len();@@ -305,7 +305,7 @@ unsafe fn utf8_to_utf16(}fn run_utf8_to_utf16(src: &[u8], dst: &mut [u16]) -> Result<usize> {- let src = core::str::from_utf8(src).map_err(|_| anyhow!("invalid utf8 encoding"))?;+ let src = core::str::from_utf8(src).map_err(|_| format_err!("invalid utf8 encoding"))?;let mut amt = 0;for (i, dst) in src.encode_utf16().zip(dst) {*dst = i.to_le();@@ -358,7 +358,7 @@ unsafe fn utf16_to_utf8(let mut dst_written = 0;for ch in core::char::decode_utf16(src_iter) {- let ch = ch.map_err(|_| anyhow!("invalid utf16 encoding"))?;+ let ch = ch.map_err(|_| format_err!("invalid utf16 encoding"))?;// If the destination doesn't have enough space for this character// then the loop is ended and this function will be called later with adiff --git a/crates/wasmtime/src/runtime/vm/const_expr.rs b/crates/wasmtime/src/runtime/vm/const_expr.rsindex 4716588088..006ed4d22b 100644--- a/crates/wasmtime/src/runtime/vm/const_expr.rs+++ b/crates/wasmtime/src/runtime/vm/const_expr.rs@@ -431,7 +431,7 @@ impl ConstExprEvaluator {fn pop(&mut self) -> Result<Val> {self.stack.pop().ok_or_else(|| {- anyhow!(+ format_err!("const expr evaluation error: attempted to pop from an empty \evaluation stack")diff --git a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling.rs b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling.rsindex 06fca8d5fe..0c78df7aef 100644--- a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling.rs+++ b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling.rs@@ -391,7 +391,7 @@ impl PoolingInstanceAllocator {pagemap: match config.pagemap_scan {Enabled::Auto => PageMap::new(),Enabled::Yes => Some(PageMap::new().ok_or_else(|| {- anyhow!(+ format_err!("required to enable PAGEMAP_SCAN but this system \does not support it")diff --git a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/gc_heap_pool.rs b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/gc_heap_pool.rsindex 2bdb7cf67e..685c8aba29 100644--- a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/gc_heap_pool.rs+++ b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/gc_heap_pool.rs@@ -90,7 +90,7 @@ impl GcHeapPool {.alloc().map(|slot| GcHeapAllocationIndex(slot.0)).ok_or_else(|| {- anyhow!(+ format_err!("maximum concurrent GC heap limit of {} reached",self.max_gc_heaps)diff --git a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/table_pool.rs b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/table_pool.rsindex 15a1a5bda1..46e1da9d96 100644--- a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/table_pool.rs+++ b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/table_pool.rs@@ -32,7 +32,7 @@ impl TablePool {let table_size = HostAlignedByteCount::new_rounded_up(crate::runtime::vm::table::NOMINAL_MAX_TABLE_ELEM_SIZE.checked_mul(config.limits.table_elements)- .ok_or_else(|| anyhow!("table size exceeds addressable memory"))?,+ .ok_or_else(|| format_err!("table size exceeds addressable memory"))?,)?;let max_total_tables = usize::try_from(config.limits.total_tables).unwrap();diff --git a/crates/wasmtime/src/runtime/vm/sys/windows/mmap.rs b/crates/wasmtime/src/runtime/vm/sys/windows/mmap.rsindex 54ca2686eb..137887600a 100644--- a/crates/wasmtime/src/runtime/vm/sys/windows/mmap.rs+++ b/crates/wasmtime/src/runtime/vm/sys/windows/mmap.rs@@ -87,7 +87,7 @@ impl Mmap {.metadata().context("failed to get file metadata")?.len();- let len = usize::try_from(len).map_err(|_| anyhow!("file too large to map"))?;+ let len = usize::try_from(len).map_err(|_| format_err!("file too large to map"))?;// Create a file mapping that allows PAGE_EXECUTE_WRITECOPY.// This enables up-to these permissions but we won't leave all