Skip to content

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

Migrate `wasmtime-wasi` to `wasmtime::error` (#12294)

Nick Fitzgeraldd73bd6323556
diff --git a/Cargo.lock b/Cargo.lock
index adbff68e37..c852ee9b83 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5063,7 +5063,6 @@ dependencies = [
name = "wasmtime-wasi"
version = "42.0.0"
dependencies = [
- "anyhow",
"async-trait",
"bitflags 2.9.4",
"bytes",
diff --git a/crates/wasi/Cargo.toml b/crates/wasi/Cargo.toml
index f4b0ad525e..9b2f95ca5d 100644
--- a/crates/wasi/Cargo.toml
+++ b/crates/wasi/Cargo.toml
@@ -18,7 +18,6 @@ workspace = true
[dependencies]
wasmtime = { workspace = true, features = ["runtime", "std"] }
wasmtime-wasi-io = { workspace = true, features = ["std"] }
-anyhow = { workspace = true }
wiggle = { workspace = true, optional = true, features = ["wasmtime"] }
tokio = { workspace = true, features = ["time", "sync", "io-std", "io-util", "rt", "rt-multi-thread", "net"] }
bytes = { workspace = true }
diff --git a/crates/wasi/src/cli.rs b/crates/wasi/src/cli.rs
index a4a5703955..018e068d60 100644
--- a/crates/wasi/src/cli.rs
+++ b/crates/wasi/src/cli.rs
@@ -266,9 +266,9 @@ impl<T: ?Sized + StdoutStream + Sync> StdoutStream for Arc<T> {
mod test {
use crate::cli::{AsyncStdoutStream, StdinStream, StdoutStream};
use crate::p2::{self, OutputStream};
- use anyhow::Result;
use bytes::Bytes;
use tokio::io::AsyncReadExt;
+ use wasmtime::Result;
#[test]
fn memory_stdin_stream() {
diff --git a/crates/wasi/src/cli/file.rs b/crates/wasi/src/cli/file.rs
index 9cbd702601..80e6d94552 100644
--- a/crates/wasi/src/cli/file.rs
+++ b/crates/wasi/src/cli/file.rs
@@ -48,14 +48,14 @@ impl OutputStream for OutputFile {
fn write(&mut self, bytes: Bytes) -> StreamResult<()> {
(&*self.file)
.write_all(&bytes)
- .map_err(|e| StreamError::LastOperationFailed(anyhow::anyhow!(e)))
+ .map_err(|e| StreamError::LastOperationFailed(wasmtime::format_err!(e)))
}
fn flush(&mut self) -> StreamResult<()> {
use std::io::Write;
self.file
.flush()
- .map_err(|e| StreamError::LastOperationFailed(anyhow::anyhow!(e)))
+ .map_err(|e| StreamError::LastOperationFailed(wasmtime::format_err!(e)))
}
fn check_write(&mut self) -> StreamResult<usize> {
@@ -124,7 +124,7 @@ impl InputStream for InputFile {
let bytes_read = self
.file
.read(&mut buf)
- .map_err(|e| StreamError::LastOperationFailed(anyhow::anyhow!(e)))?;
+ .map_err(|e| StreamError::LastOperationFailed(wasmtime::format_err!(e)))?;
if bytes_read == 0 {
return Err(StreamError::Closed);
}
diff --git a/crates/wasi/src/cli/stdout.rs b/crates/wasi/src/cli/stdout.rs
index 2626d1613a..9d0a213e52 100644
--- a/crates/wasi/src/cli/stdout.rs
+++ b/crates/wasi/src/cli/stdout.rs
@@ -78,7 +78,7 @@ impl OutputStream for StdioOutputStream {
StdioOutputStream::Stdout => std::io::stdout().write_all(&bytes),
StdioOutputStream::Stderr => std::io::stderr().write_all(&bytes),
}
- .map_err(|e| p2::StreamError::LastOperationFailed(anyhow::anyhow!(e)))
+ .map_err(|e| p2::StreamError::LastOperationFailed(wasmtime::format_err!(e)))
}
fn flush(&mut self) -> p2::StreamResult<()> {
@@ -86,7 +86,7 @@ impl OutputStream for StdioOutputStream {
StdioOutputStream::Stdout => std::io::stdout().flush(),
StdioOutputStream::Stderr => std::io::stderr().flush(),
}
- .map_err(|e| p2::StreamError::LastOperationFailed(anyhow::anyhow!(e)))
+ .map_err(|e| p2::StreamError::LastOperationFailed(wasmtime::format_err!(e)))
}
fn check_write(&mut self) -> p2::StreamResult<usize> {
diff --git a/crates/wasi/src/ctx.rs b/crates/wasi/src/ctx.rs
index b74df57dd0..3fa8d3c836 100644
--- a/crates/wasi/src/ctx.rs
+++ b/crates/wasi/src/ctx.rs
@@ -4,7 +4,6 @@ use crate::filesystem::{Dir, WasiFilesystemCtx};
use crate::random::WasiRandomCtx;
use crate::sockets::{SocketAddrCheck, SocketAddrUse, WasiSocketsCtx};
use crate::{DirPerms, FilePerms, OpenMode};
-use anyhow::Result;
use cap_rand::RngCore;
use cap_std::ambient_authority;
use std::future::Future;
@@ -13,6 +12,7 @@ use std::net::SocketAddr;
use std::path::Path;
use std::pin::Pin;
use tokio::io::{stderr, stdin, stdout};
+use wasmtime::Result;
/// Builder-style structure used to create a [`WasiCtx`].
///
diff --git a/crates/wasi/src/error.rs b/crates/wasi/src/error.rs
index f92317c1fe..35865ab5a3 100644
--- a/crates/wasi/src/error.rs
+++ b/crates/wasi/src/error.rs
@@ -23,7 +23,7 @@ impl std::error::Error for I32Exit {}
/// either:
///
/// * A custom error type `T`
-/// * A trap, represented as `anyhow::Error`
+/// * A trap, represented as `wasmtime::Error`
///
/// This error is created through either the `::trap` constructor representing a
/// full-fledged trap or the `From<T>` constructor which is intended to be used
@@ -43,19 +43,19 @@ impl std::error::Error for I32Exit {}
/// `bindgen!` macro.
#[repr(transparent)]
pub struct TrappableError<T> {
- err: anyhow::Error,
+ err: wasmtime::Error,
_marker: marker::PhantomData<T>,
}
impl<T> TrappableError<T> {
- pub fn trap(err: impl Into<anyhow::Error>) -> TrappableError<T> {
+ pub fn trap(err: impl Into<wasmtime::Error>) -> TrappableError<T> {
TrappableError {
err: err.into(),
_marker: marker::PhantomData,
}
}
- pub fn downcast(self) -> anyhow::Result<T>
+ pub fn downcast(self) -> wasmtime::Result<T>
where
T: Error + Send + Sync + 'static,
{
diff --git a/crates/wasi/src/filesystem.rs b/crates/wasi/src/filesystem.rs
index 0d640e40ab..8b55b2cae6 100644
--- a/crates/wasi/src/filesystem.rs
+++ b/crates/wasi/src/filesystem.rs
@@ -1,12 +1,12 @@
use crate::clocks::Datetime;
use crate::runtime::{AbortOnDropJoinHandle, spawn_blocking};
-use anyhow::Context as _;
use cap_fs_ext::{FileTypeExt as _, MetadataExt as _};
use fs_set_times::SystemTimeSpec;
use std::collections::hash_map;
use std::sync::Arc;
use tracing::debug;
use wasmtime::component::{HasData, Resource, ResourceTable};
+use wasmtime::error::Context as _;
/// A helper struct which implements [`HasData`] for the `wasi:filesystem` APIs.
///
diff --git a/crates/wasi/src/p0.rs b/crates/wasi/src/p0.rs
index 48c82a48cd..ef37ae43a1 100644
--- a/crates/wasi/src/p0.rs
+++ b/crates/wasi/src/p0.rs
@@ -12,14 +12,14 @@ use wiggle::{GuestError, GuestMemory, GuestPtr};
pub fn add_to_linker_async<T: Send + 'static>(
linker: &mut wasmtime::Linker<T>,
f: impl Fn(&mut T) -> &mut WasiP1Ctx + Copy + Send + Sync + 'static,
-) -> anyhow::Result<()> {
+) -> wasmtime::Result<()> {
wasi_unstable::add_to_linker(linker, f)
}
pub fn add_to_linker_sync<T: Send + 'static>(
linker: &mut wasmtime::Linker<T>,
f: impl Fn(&mut T) -> &mut WasiP1Ctx + Copy + Send + Sync + 'static,
-) -> anyhow::Result<()> {
+) -> wasmtime::Result<()> {
sync::add_wasi_unstable_to_linker(linker, f)
}
@@ -38,8 +38,8 @@ wiggle::from_witx!({
});
mod sync {
- use anyhow::Result;
use std::future::Future;
+ use wasmtime::Result;
wiggle::wasmtime_integration!({
witx: ["witx/p0/wasi_unstable.witx"],
@@ -550,7 +550,7 @@ impl<T: Snapshot1 + Send> wasi_unstable::WasiUnstable for T {
&mut self,
memory: &mut GuestMemory<'_>,
status: types::Exitcode,
- ) -> anyhow::Error {
+ ) -> wasmtime::Error {
Snapshot1::proc_exit(self, memory, status)
}
@@ -585,7 +585,7 @@ impl<T: Snapshot1 + Send> wasi_unstable::WasiUnstable for T {
_ri_data: types::IovecArray,
_ri_flags: types::Riflags,
) -> Result<(types::Size, types::Roflags), Error> {
- Err(Error::trap(anyhow::Error::msg("sock_recv unsupported")))
+ Err(Error::trap(wasmtime::Error::msg("sock_recv unsupported")))
}
fn sock_send(
@@ -595,7 +595,7 @@ impl<T: Snapshot1 + Send> wasi_unstable::WasiUnstable for T {
_si_data: types::CiovecArray,
_si_flags: types::Siflags,
) -> Result<types::Size, Error> {
- Err(Error::trap(anyhow::Error::msg("sock_send unsupported")))
+ Err(Error::trap(wasmtime::Error::msg("sock_send unsupported")))
}
fn sock_shutdown(
@@ -604,7 +604,9 @@ impl<T: Snapshot1 + Send> wasi_unstable::WasiUnstable for T {
_fd: types::Fd,
_how: types::Sdflags,
) -> Result<(), Error> {
- Err(Error::trap(anyhow::Error::msg("sock_shutdown unsupported")))
+ Err(Error::trap(wasmtime::Error::msg(
+ "sock_shutdown unsupported",
+ )))
}
}
diff --git a/crates/wasi/src/p1.rs b/crates/wasi/src/p1.rs
index 0eea9cd897..cda806f4af 100644
--- a/crates/wasi/src/p1.rs
+++ b/crates/wasi/src/p1.rs
@@ -76,7 +76,6 @@ use crate::p2::bindings::{
};
use crate::p2::{FsError, IsATTY};
use crate::{ResourceTable, WasiCtx, WasiCtxView, WasiView};
-use anyhow::{Context, bail};
use std::collections::{BTreeMap, BTreeSet, HashSet, btree_map};
use std::mem::{self, size_of, size_of_val};
use std::slice;
@@ -84,6 +83,7 @@ use std::sync::Arc;
use std::sync::atomic::{AtomicU64, Ordering};
use system_interface::fs::FileIoExt;
use wasmtime::component::Resource;
+use wasmtime::{bail, error::Context as _};
use wasmtime_wasi_io::{
bindings::wasi::io::streams,
streams::{StreamError, StreamResult},
@@ -718,7 +718,7 @@ enum FdWrite {
pub fn add_to_linker_async<T: Send + 'static>(
linker: &mut wasmtime::Linker<T>,
f: impl Fn(&mut T) -> &mut WasiP1Ctx + Copy + Send + Sync + 'static,
-) -> anyhow::Result<()> {
+) -> wasmtime::Result<()> {
crate::p1::wasi_snapshot_preview1::add_to_linker(linker, f)
}
@@ -792,7 +792,7 @@ pub fn add_to_linker_async<T: Send + 'static>(
pub fn add_to_linker_sync<T: Send + 'static>(
linker: &mut wasmtime::Linker<T>,
f: impl Fn(&mut T) -> &mut WasiP1Ctx + Copy + Send + Sync + 'static,
-) -> anyhow::Result<()> {
+) -> wasmtime::Result<()> {
sync::add_wasi_snapshot_preview1_to_linker(linker, f)
}
@@ -815,8 +815,8 @@ wiggle::from_witx!({
});
pub(crate) mod sync {
- use anyhow::Result;
use std::future::Future;
+ use wasmtime::Result;
wiggle::wasmtime_integration!({
witx: ["witx/p1/wasi_snapshot_preview1.witx"],
@@ -945,7 +945,7 @@ impl From<types::Advice> for filesystem::Advice {
}
impl TryFrom<filesystem::DescriptorType> for types::Filetype {
- type Error = anyhow::Error;
+ type Error = wasmtime::Error;
fn try_from(ty: filesystem::DescriptorType) -> Result<Self, Self::Error> {
match ty {
@@ -2552,10 +2552,10 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiP1Ctx {
&mut self,
_memory: &mut GuestMemory<'_>,
status: types::Exitcode,
- ) -> anyhow::Error {
+ ) -> wasmtime::Error {
// Check that the status is within WASI's range.
if status >= 126 {
- return anyhow::Error::msg("exit with invalid exit status outside of [0..126)");
+ return wasmtime::Error::msg("exit with invalid exit status outside of [0..126)");
}
crate::I32Exit(status as i32).into()
}
diff --git a/crates/wasi/src/p2/filesystem.rs b/crates/wasi/src/p2/filesystem.rs
index 608349dcbe..e01129710f 100644
--- a/crates/wasi/src/p2/filesystem.rs
+++ b/crates/wasi/src/p2/filesystem.rs
@@ -3,10 +3,10 @@ use crate::filesystem::File;
use crate::p2::bindings::filesystem::types;
use crate::p2::{InputStream, OutputStream, Pollable, StreamError, StreamResult};
use crate::runtime::AbortOnDropJoinHandle;
-use anyhow::anyhow;
use bytes::{Bytes, BytesMut};
use std::io;
use std::mem;
+use wasmtime::format_err;
pub type FsResult<T> = Result<T, FsError>;
@@ -287,7 +287,7 @@ impl OutputStream for FileOutputStream {
OutputState::Closed => return Err(StreamError::Closed),
OutputState::Waiting(_) | OutputState::Error(_) => {
// a write is pending - this call was not permitted
- return Err(StreamError::Trap(anyhow!(
+ return Err(StreamError::Trap(format_err!(
"write not permitted: check_write not called first"
)));
}
diff --git a/crates/wasi/src/p2/host/clocks.rs b/crates/wasi/src/p2/host/clocks.rs
index 95dee36fcf..f4ec0d99fe 100644
--- a/crates/wasi/src/p2/host/clocks.rs
+++ b/crates/wasi/src/p2/host/clocks.rs
@@ -47,7 +47,7 @@ impl TryFrom<SystemTime> for Datetime {
}
impl wall_clock::Host for WasiClocksCtxView<'_> {
- fn now(&mut self) -> anyhow::Result<Datetime> {
+ fn now(&mut self) -> wasmtime::Result<Datetime> {
let now = self.ctx.wall_clock.now();
Ok(Datetime {
seconds: now.as_secs(),
@@ -55,7 +55,7 @@ impl wall_clock::Host for WasiClocksCtxView<'_> {
})
}
- fn resolution(&mut self) -> anyhow::Result<Datetime> {
+ fn resolution(&mut self) -> wasmtime::Result<Datetime> {
let res = self.ctx.wall_clock.resolution();
Ok(Datetime {
seconds: res.as_secs(),
@@ -67,7 +67,7 @@ impl wall_clock::Host for WasiClocksCtxView<'_> {
fn subscribe_to_duration(
table: &mut wasmtime::component::ResourceTable,
duration: tokio::time::Duration,
-) -> anyhow::Result<Resource<DynPollable>> {
+) -> wasmtime::Result<Resource<DynPollable>> {
let sleep = if duration.is_zero() {
table.push(Deadline::Past)?
} else if let Some(deadline) = tokio::time::Instant::now().checked_add(duration) {
@@ -84,15 +84,15 @@ fn subscribe_to_duration(
}
impl monotonic_clock::Host for WasiClocksCtxView<'_> {
- fn now(&mut self) -> anyhow::Result<Instant> {
+ fn now(&mut self) -> wasmtime::Result<Instant> {
Ok(self.ctx.monotonic_clock.now())
}
- fn resolution(&mut self) -> anyhow::Result<Instant> {
+ fn resolution(&mut self) -> wasmtime::Result<Instant> {
Ok(self.ctx.monotonic_clock.resolution())
}
- fn subscribe_instant(&mut self, when: Instant) -> anyhow::Result<Resource<DynPollable>> {
+ fn subscribe_instant(&mut self, when: Instant) -> wasmtime::Result<Resource<DynPollable>> {
let clock_now = self.ctx.monotonic_clock.now();
let duration = if when > clock_now {
Duration::from_nanos(when - clock_now)
@@ -105,7 +105,7 @@ impl monotonic_clock::Host for WasiClocksCtxView<'_> {
fn subscribe_duration(
&mut self,
duration: WasiDuration,
- ) -> anyhow::Result<Resource<DynPollable>> {
+ ) -> wasmtime::Result<Resource<DynPollable>> {
subscribe_to_duration(self.table, Duration::from_nanos(duration))
}
}
diff --git a/crates/wasi/src/p2/host/env.rs b/crates/wasi/src/p2/host/env.rs
index 0ca8d1c703..550f9938ba 100644
--- a/crates/wasi/src/p2/host/env.rs
+++ b/crates/wasi/src/p2/host/env.rs
@@ -2,13 +2,13 @@ use crate::cli::WasiCliCtxView;
use crate::p2::bindings::cli::environment;
impl environment::Host for WasiCliCtxView<'_> {
- fn get_environment(&mut self) -> anyhow::Result<Vec<(String, String)>> {
+ fn get_environment(&mut self) -> wasmtime::Result<Vec<(String, String)>> {
Ok(self.ctx.environment.clone())
}
- fn get_arguments(&mut self) -> anyhow::Result<Vec<String>> {
+ fn get_arguments(&mut self) -> wasmtime::Result<Vec<String>> {
Ok(self.ctx.arguments.clone())
}
- fn initial_cwd(&mut self) -> anyhow::Result<Option<String>> {
+ fn initial_cwd(&mut self) -> wasmtime::Result<Option<String>> {
Ok(self.ctx.initial_cwd.clone())
}
}
diff --git a/crates/wasi/src/p2/host/exit.rs b/crates/wasi/src/p2/host/exit.rs
index 3e5253f4b8..76cb8dcfe9 100644
--- a/crates/wasi/src/p2/host/exit.rs
+++ b/crates/wasi/src/p2/host/exit.rs
@@ -3,15 +3,15 @@ use crate::cli::WasiCliCtxView;
use crate::p2::bindings::cli::exit;
impl exit::Host for WasiCliCtxView<'_> {
- fn exit(&mut self, status: Result<(), ()>) -> anyhow::Result<()> {
+ fn exit(&mut self, status: Result<(), ()>) -> wasmtime::Result<()> {
let status = match status {
Ok(()) => 0,
Err(()) => 1,
};
- Err(anyhow::anyhow!(I32Exit(status)))
+ Err(wasmtime::format_err!(I32Exit(status)))
}
- fn exit_with_code(&mut self, status_code: u8) -> anyhow::Result<()> {
- Err(anyhow::anyhow!(I32Exit(status_code.into())))
+ fn exit_with_code(&mut self, status_code: u8) -> wasmtime::Result<()> {
+ Err(wasmtime::format_err!(I32Exit(status_code.into())))
}
}
diff --git a/crates/wasi/src/p2/host/filesystem.rs b/crates/wasi/src/p2/host/filesystem.rs
index 7e10d6d665..1bd63d3b3f 100644
--- a/crates/wasi/src/p2/host/filesystem.rs
+++ b/crates/wasi/src/p2/host/filesystem.rs
@@ -19,14 +19,14 @@ impl preopens::Host for WasiFilesystemCtxView<'_> {
}
impl types::Host for WasiFilesystemCtxView<'_> {
- fn convert_error_code(&mut self, err: FsError) -> anyhow::Result<ErrorCode> {
+ fn convert_error_code(&mut self, err: FsError) -> wasmtime::Result<ErrorCode> {
err.downcast()
}
fn filesystem_error_code(
&mut self,
- err: Resource<anyhow::Error>,
- ) -> anyhow::Result<Option<ErrorCode>> {
+ err: Resource<wasmtime::Error>,
+ ) -> wasmtime::Result<Option<ErrorCode>> {
let err = self.table.get(&err)?;
// Currently `err` always comes from the stream implementation which
@@ -303,7 +303,7 @@ impl HostDescriptor for WasiFilesystemCtxView<'_> {
Ok(fd)
}
- fn drop(&mut self, fd: Resource<types::Descriptor>) -> anyhow::Result<()> {
+ fn drop(&mut self, fd: Resource<types::Descriptor>) -> wasmtime::Result<()> {
// The Drop will close the file/dir, but if the close syscall
// blocks the thread, I will face god and walk backwards into hell.
// tokio::fs::File just uses std::fs::File's Drop impl to close, so
@@ -436,7 +436,7 @@ impl HostDescriptor for WasiFilesystemCtxView<'_> {
&mut self,
a: Resource<types::Descriptor>,
b: Resource<types::Descriptor>,
- ) -> anyhow::Result<bool> {
+ ) -> wasmtime::Result<bool> {
let descriptor_a = self.table.get(&a)?;
let descriptor_b = self.table.get(&b)?;
descriptor_a.is_same_object(descriptor_b).await
@@ -470,7 +470,7 @@ impl HostDirectoryEntryStream for WasiFilesystemCtxView<'_> {
readdir.next()
}
- fn drop(&mut self, stream: Resource<types::DirectoryEntryStream>) -> anyhow::Result<()> {
+ fn drop(&mut self, stream: Resource<types::DirectoryEntryStream>) -> wasmtime::Result<()> {
self.table.delete(stream)?;
Ok(())
}
diff --git a/crates/wasi/src/p2/host/filesystem/sync.rs b/crates/wasi/src/p2/host/filesystem/sync.rs
index f20a986bf9..c0e974fd6d 100644
--- a/crates/wasi/src/p2/host/filesystem/sync.rs
+++ b/crates/wasi/src/p2/host/filesystem/sync.rs
@@ -7,14 +7,14 @@ use crate::runtime::in_tokio;
use wasmtime::component::Resource;
impl sync_filesystem::Host for WasiFilesystemCtxView<'_> {
- fn convert_error_code(&mut self, err: FsError) -> anyhow::Result<sync_filesystem::ErrorCode> {
+ fn convert_error_code(&mut self, err: FsError) -> wasmtime::Result<sync_filesystem::ErrorCode> {
Ok(async_filesystem::Host::convert_error_code(self, err)?.into())
}
fn filesystem_error_code(
&mut self,
err: Resource<streams::Error>,
- ) -> anyhow::Result<Option<sync_filesystem::ErrorCode>> {
+ ) -> wasmtime::Result<Option<sync_filesystem::ErrorCode>> {
Ok(async_filesystem::Host::filesystem_error_code(self, err)?.map(|e| e.into()))
}
}
@@ -191,7 +191,7 @@ impl sync_filesystem::HostDescriptor for WasiFilesystemCtxView<'_> {
})
}
- fn drop(&mut self, fd: Resource<sync_filesystem::Descriptor>) -> anyhow::Result<()> {
+ fn drop(&mut self, fd: Resource<sync_filesystem::Descriptor>) -> wasmtime::Result<()> {
async_filesystem::HostDescriptor::drop(self, fd)
}
@@ -277,7 +277,7 @@ impl sync_filesystem::HostDescriptor for WasiFilesystemCtxView<'_> {
&mut self,
a: Resource<sync_filesystem::Descriptor>,
b: Resource<sync_filesystem::Descriptor>,
- ) -> anyhow::Result<bool> {
+ ) -> wasmtime::Result<bool> {
in_tokio(async { async_filesystem::HostDescriptor::is_same_object(self, a, b).await })
}
fn metadata_hash(
@@ -317,7 +317,7 @@ impl sync_filesystem::HostDirectoryEntryStream for WasiFilesystemCtxView<'_> {
fn drop(
&mut self,
stream: Resource<sync_filesystem::DirectoryEntryStream>,
- ) -> anyhow::Result<()> {
+ ) -> wasmtime::Result<()> {
async_filesystem::HostDirectoryEntryStream::drop(self, stream)
}
}
diff --git a/crates/wasi/src/p2/host/instance_network.rs b/crates/wasi/src/p2/host/instance_network.rs
index 9029181d0a..c985d40645 100644
--- a/crates/wasi/src/p2/host/instance_network.rs
+++ b/crates/wasi/src/p2/host/instance_network.rs
@@ -4,7 +4,7 @@ use crate::sockets::WasiSocketsCtxView;
use wasmtime::component::Resource;
impl instance_network::Host for WasiSocketsCtxView<'_> {
- fn instance_network(&mut self) -> Result<Resource<Network>, anyhow::Error> {
+ fn instance_network(&mut self) -> Result<Resource<Network>, wasmtime::Error> {
let network = Network {
socket_addr_check: self.ctx.socket_addr_check.clone(),
allow_ip_name_lookup: self.ctx.allowed_network_uses.ip_name_lookup,
diff --git a/crates/wasi/src/p2/host/io.rs b/crates/wasi/src/p2/host/io.rs
index 1baa67e01d..4ab4e8b09b 100644
--- a/crates/wasi/src/p2/host/io.rs
+++ b/crates/wasi/src/p2/host/io.rs
@@ -20,13 +20,13 @@ impl From<async_streams::StreamError> for streams::StreamError {
}
impl streams::Host for ResourceTable {
- fn convert_stream_error(&mut self, err: StreamError) -> anyhow::Result<streams::StreamError> {
+ fn convert_stream_error(&mut self, err: StreamError) -> wasmtime::Result<streams::StreamError> {
Ok(AsyncHost::convert_stream_error(self, err)?.into())
}
}
impl streams::HostOutputStream for ResourceTable {
- fn drop(&mut self, stream: Resource<OutputStream>) -> anyhow::Result<()> {
+ fn drop(&mut self, stream: Resource<OutputStream>) -> wasmtime::Result<()> {
in_tokio(async { AsyncHostOutputStream::drop(self, stream).await })
}
@@ -58,7 +58,10 @@ impl streams::HostOutputStream for ResourceTable {
})
}
- fn subscribe(&mut self, stream: Resource<OutputStream>) -> anyhow::Result<Resource<Pollable>> {
+ fn subscribe(
+ &mut self,
+ stream: Resource<OutputStream>,
+ ) -> wasmtime::Result<Resource<Pollable>> {
Ok(AsyncHostOutputStream::subscribe(self, stream)?)
}
@@ -99,7 +102,7 @@ impl streams::HostOutputStream for ResourceTable {
}
impl streams::HostInputStream for ResourceTable {
- fn drop(&mut self, stream: Resource<InputStream>) -> anyhow::Result<()> {
+ fn drop(&mut self, stream: Resource<InputStream>) -> wasmtime::Result<()> {
in_tokio(async { AsyncHostInputStream::drop(self, stream).await })
}
@@ -119,7 +122,7 @@ impl streams::HostInputStream for ResourceTable {
in_tokio(async { AsyncHostInputStream::blocking_skip(self, stream, len).await })
}
- fn subscribe(&mut self, stream: Resource<InputStream>) -> anyhow::Result<Resource<Pollable>> {
+ fn subscribe(&mut self, stream: Resource<InputStream>) -> wasmtime::Result<Resource<Pollable>> {
AsyncHostInputStream::subscribe(self, stream)
}
}
diff --git a/crates/wasi/src/p2/host/network.rs b/crates/wasi/src/p2/host/network.rs
index e0fd31f477..0d0b06559b 100644
--- a/crates/wasi/src/p2/host/network.rs
+++ b/crates/wasi/src/p2/host/network.rs
@@ -5,17 +5,17 @@ use crate::p2::bindings::sockets::network::{
};
use crate::sockets::WasiSocketsCtxView;
use crate::sockets::util::{from_ipv4_addr, from_ipv6_addr, to_ipv4_addr, to_ipv6_addr};
-use anyhow::Error;
use rustix::io::Errno;
use std::io;
+use wasmtime::Error;
use wasmtime::component::Resource;
impl network::Host for WasiSocketsCtxView<'_> {
- fn convert_error_code(&mut self, error: SocketError) -> anyhow::Result<ErrorCode> {
+ fn convert_error_code(&mut self, error: SocketError) -> wasmtime::Result<ErrorCode> {
error.downcast()
}
- fn network_error_code(&mut self, err: Resource<Error>) -> anyhow::Result<Option<ErrorCode>> {
+ fn network_error_code(&mut self, err: Resource<Error>) -> wasmtime::Result<Option<ErrorCode>> {
let err = self.table.get(&err)?;
if let Some(err) = err.downcast_ref::<std::io::Error>() {
@@ -27,7 +27,7 @@ impl network::Host for WasiSocketsCtxView<'_> {
}
impl crate::p2::bindings::sockets::network::HostNetwork for WasiSocketsCtxView<'_> {
- fn drop(&mut self, this: Resource<network::Network>) -> Result<(), anyhow::Error> {
+ fn drop(&mut self, this: Resource<network::Network>) -> Result<(), wasmtime::Error> {
self.table.delete(this)?;
Ok(())
diff --git a/crates/wasi/src/p2/host/random.rs b/crates/wasi/src/p2/host/random.rs
index aac8457a9f..86bf5d374e 100644
--- a/crates/wasi/src/p2/host/random.rs
+++ b/crates/wasi/src/p2/host/random.rs
@@ -3,33 +3,33 @@ use crate::random::WasiRandomCtx;
use cap_rand::{Rng, distributions::Standard};
impl random::Host for WasiRandomCtx {
- fn get_random_bytes(&mut self, len: u64) -> anyhow::Result<Vec<u8>> {
+ fn get_random_bytes(&mut self, len: u64) -> wasmtime::Result<Vec<u8>> {
Ok((&mut self.random)
.sample_iter(Standard)
.take(len as usize)
.collect())
}
- fn get_random_u64(&mut self) -> anyhow::Result<u64> {
+ fn get_random_u64(&mut self) -> wasmtime::Result<u64> {
Ok(self.random.sample(Standard))
}
}
impl insecure::Host for WasiRandomCtx {
- fn get_insecure_random_bytes(&mut self, len: u64) -> anyhow::Result<Vec<u8>> {
+ fn get_insecure_random_bytes(&mut self, len: u64) -> wasmtime::Result<Vec<u8>> {
Ok((&mut self.insecure_random)
.sample_iter(Standard)
.take(len as usize)
.collect())
}
- fn get_insecure_random_u64(&mut self) -> anyhow::Result<u64> {
+ fn get_insecure_random_u64(&mut self) -> wasmtime::Result<u64> {
Ok(self.insecure_random.sample(Standard))
}
}
impl insecure_seed::Host for WasiRandomCtx {
- fn insecure_seed(&mut self) -> anyhow::Result<(u64, u64)> {
+ fn insecure_seed(&mut self) -> wasmtime::Result<(u64, u64)> {
let seed: u128 = self.insecure_random_seed;
Ok((seed as u64, (seed >> 64) as u64))
}
diff --git a/crates/wasi/src/p2/host/tcp.rs b/crates/wasi/src/p2/host/tcp.rs
index a0ac1ee9fa..47d638dd4b 100644
--- a/crates/wasi/src/p2/host/tcp.rs
+++ b/crates/wasi/src/p2/host/tcp.rs
@@ -123,7 +123,7 @@ impl crate::p2::host::tcp::tcp::HostTcpSocket for WasiSocketsCtxView<'_> {
Ok(socket.remote_address()?.into())
}
- fn is_listening(&mut self, this: Resource<TcpSocket>) -> Result<bool, anyhow::Error> {
+ fn is_listening(&mut self, this: Resource<TcpSocket>) -> Result<bool, wasmtime::Error> {
let socket = self.table.get(&this)?;
Ok(socket.is_listening())
@@ -132,7 +132,7 @@ impl crate::p2::host::tcp::tcp::HostTcpSocket for WasiSocketsCtxView<'_> {
fn address_family(
&mut self,
this: Resource<TcpSocket>,
- ) -> Result<IpAddressFamily, anyhow::Error> {
+ ) -> Result<IpAddressFamily, wasmtime::Error> {
let socket = self.table.get(&this)?;
Ok(socket.address_family().into())
}
@@ -240,7 +240,7 @@ impl crate::p2::host::tcp::tcp::HostTcpSocket for WasiSocketsCtxView<'_> {
Ok(())
}
- fn subscribe(&mut self, this: Resource<TcpSocket>) -> anyhow::Result<Resource<DynPollable>> {
+ fn subscribe(&mut self, this: Resource<TcpSocket>) -> wasmtime::Result<Resource<DynPollable>> {
wasmtime_wasi_io::poll::subscribe(self.table, this)
}
@@ -262,7 +262,7 @@ impl crate::p2::host::tcp::tcp::HostTcpSocket for WasiSocketsCtxView<'_> {
Ok(())
}
- fn drop(&mut self, this: Resource<TcpSocket>) -> Result<(), anyhow::Error> {
+ fn drop(&mut self, this: Resource<TcpSocket>) -> Result<(), wasmtime::Error> {
// As in the filesystem implementation, we assume closing a socket
// doesn't block.
let dropped = self.table.delete(this)?;
diff --git a/crates/wasi/src/p2/host/udp.rs b/crates/wasi/src/p2/host/udp.rs
index c9ce15a403..1ef8350399 100644
--- a/crates/wasi/src/p2/host/udp.rs
+++ b/crates/wasi/src/p2/host/udp.rs
@@ -6,11 +6,11 @@ use crate::sockets::util::{is_valid_address_family, is_valid_remote_address};
use crate::sockets::{
MAX_UDP_DATAGRAM_SIZE, SocketAddrUse, SocketAddressFamily, UdpSocket, WasiSocketsCtxView,
};
-use anyhow::anyhow;
use async_trait::async_trait;
use std::net::SocketAddr;
use tokio::io::Interest;
use wasmtime::component::Resource;
+use wasmtime::format_err;
use wasmtime_wasi_io::poll::DynPollable;
impl udp::Host for WasiSocketsCtxView<'_> {}
@@ -52,7 +52,9 @@ impl udp::HostUdpSocket for WasiSocketsCtxView<'_> {
.any(|c| c.is::<IncomingDatagramStream>() || c.is::<OutgoingDatagramStream>());
if has_active_streams {
- return Err(SocketError::trap(anyhow!("UDP streams not dropped yet")));
+ return Err(SocketError::trap(format_err!(
+ "UDP streams not dropped yet"
+ )));
}
let socket = self.table.get_mut(&this)?;
@@ -113,7 +115,7 @@ impl udp::HostUdpSocket for WasiSocketsCtxView<'_> {
fn address_family(
&mut self,
this: Resource<udp::UdpSocket>,
- ) -> Result<IpAddressFamily, anyhow::Error> {
+ ) -> Result<IpAddressFamily, wasmtime::Error> {
let socket = self.table.get(&this)?;
Ok(socket.address_family().into())
}
@@ -159,11 +161,11 @@ impl udp::HostUdpSocket for WasiSocketsCtxView<'_> {
Ok(())
}
- fn subscribe(&mut self, this: Resource<UdpSocket>) -> anyhow::Result<Resource<DynPollable>> {
+ fn subscribe(&mut self, this: Resource<UdpSocket>) -> wasmtime::Result<Resource<DynPollable>> {
wasmtime_wasi_io::poll::subscribe(self.table, this)
}
- fn drop(&mut self, this: Resource<udp::UdpSocket>) -> Result<(), anyhow::Error> {
+ fn drop(&mut self, this: Resource<udp::UdpSocket>) -> Result<(), wasmtime::Error> {
// As in the filesystem implementation, we assume closing a socket
// doesn't block.
let dropped = self.table.delete(this)?;
@@ -243,11 +245,11 @@ impl udp::HostIncomingDatagramStream for WasiSocketsCtxView<'_> {
fn subscribe(
&mut self,
this: Resource<udp::IncomingDatagramStream>,
- ) -> anyhow::Result<Resource<DynPollable>> {
+ ) -> wasmtime::Result<Resource<DynPollable>> {
wasmtime_wasi_io::poll::subscribe(self.table, this)
}
- fn drop(&mut self, this: Resource<udp::IncomingDatagramStream>) -> Result<(), anyhow::Error> {
+ fn drop(&mut self, this: Resource<udp::IncomingDatagramStream>) -> Result<(), wasmtime::Error> {
// As in the filesystem implementation, we assume closing a socket
// doesn't block.
let dropped = self.table.delete(this)?;
@@ -337,12 +339,12 @@ impl udp::HostOutgoingDatagramStream for WasiSocketsCtxView<'_> {
stream.send_state = SendState::Idle;
}
SendState::Permitted(_) => {
- return Err(SocketError::trap(anyhow::anyhow!(
+ return Err(SocketError::trap(wasmtime::format_err!(
"unpermitted: argument exceeds permitted size"
)));
}
SendState::Idle | SendState::Waiting => {
- return Err(SocketError::trap(anyhow::anyhow!(
+ return Err(SocketError::trap(wasmtime::format_err!(
"unpermitted: must call check-send first"
)));
}
@@ -377,11 +379,11 @@ impl udp::HostOutgoingDatagramStream for WasiSocketsCtxView<'_> {
fn subscribe(
&mut self,
this: Resource<udp::OutgoingDatagramStream>,
- ) -> anyhow::Result<Resource<DynPollable>> {
+ ) -> wasmtime::Result<Resource<DynPollable>> {
wasmtime_wasi_io::poll::subscribe(self.table, this)
}
- fn drop(&mut self, this: Resource<udp::OutgoingDatagramStream>) -> Result<(), anyhow::Error> {
+ fn drop(&mut self, this: Resource<udp::OutgoingDatagramStream>) -> Result<(), wasmtime::Error> {
// As in the filesystem implementation, we assume closing a socket
// doesn't block.
let dropped = self.table.delete(this)?;
diff --git a/crates/wasi/src/p2/ip_name_lookup.rs b/crates/wasi/src/p2/ip_name_lookup.rs
index b8cc63986d..3fa0e7433a 100644
--- a/crates/wasi/src/p2/ip_name_lookup.rs
+++ b/crates/wasi/src/p2/ip_name_lookup.rs
@@ -3,11 +3,11 @@ use crate::p2::bindings::sockets::ip_name_lookup::{Host, HostResolveAddressStrea
use crate::p2::bindings::sockets::network::{ErrorCode, IpAddress, Network};
use crate::runtime::{AbortOnDropJoinHandle, spawn_blocking};
use crate::sockets::WasiSocketsCtxView;
-use anyhow::Result;
use std::mem;
use std::net::ToSocketAddrs;
use std::pin::Pin;
use std::vec;
+use wasmtime::Result;
use wasmtime::component::Resource;
use wasmtime_wasi_io::poll::{DynPollable, Pollable, subscribe};
diff --git a/crates/wasi/src/p2/mod.rs b/crates/wasi/src/p2/mod.rs
index 25974c6fae..a11b3c8304 100644
--- a/crates/wasi/src/p2/mod.rs
+++ b/crates/wasi/src/p2/mod.rs
@@ -311,7 +311,7 @@ pub use wasmtime_wasi_io::streams::{
/// }
/// }
/// ```
-pub fn add_to_linker_async<T: WasiView>(linker: &mut Linker<T>) -> anyhow::Result<()> {
+pub fn add_to_linker_async<T: WasiView>(linker: &mut Linker<T>) -> wasmtime::Result<()> {
let options = bindings::LinkOptions::default();
add_to_linker_with_options_async(linker, &options)
}
@@ -320,7 +320,7 @@ pub fn add_to_linker_async<T: WasiView>(linker: &mut Linker<T>) -> anyhow::Resul
pub fn add_to_linker_with_options_async<T: WasiView>(
linker: &mut Linker<T>,
options: &bindings::LinkOptions,
-) -> anyhow::Result<()> {
+) -> wasmtime::Result<()> {
add_async_io_to_linker(linker)?;
add_nonblocking_to_linker(linker, options)?;
@@ -335,7 +335,7 @@ pub fn add_to_linker_with_options_async<T: WasiView>(
fn add_nonblocking_to_linker<'a, T: WasiView, O>(
linker: &mut Linker<T>,
options: &'a O,
-) -> anyhow::Result<()>
+) -> wasmtime::Result<()>
where
bindings::sockets::network::LinkOptions: From<&'a O>,
bindings::cli::exit::LinkOptions: From<&'a O>,
@@ -371,7 +371,7 @@ where
/// present in the `wasi:http/proxy` world.
pub fn add_to_linker_proxy_interfaces_async<T: WasiView>(
linker: &mut Linker<T>,
-) -> anyhow::Result<()> {
+) -> wasmtime::Result<()> {
add_async_io_to_linker(linker)?;
add_proxy_interfaces_nonblocking(linker)
}
@@ -381,12 +381,12 @@ pub fn add_to_linker_proxy_interfaces_async<T: WasiView>(
#[doc(hidden)]
pub fn add_to_linker_proxy_interfaces_sync<T: WasiView>(
linker: &mut Linker<T>,
-) -> anyhow::Result<()> {
+) -> wasmtime::Result<()> {
add_sync_wasi_io(linker)?;
add_proxy_interfaces_nonblocking(linker)
}
-fn add_proxy_interfaces_nonblocking<T: WasiView>(linker: &mut Linker<T>) -> anyhow::Result<()> {
+fn add_proxy_interfaces_nonblocking<T: WasiView>(linker: &mut Linker<T>) -> wasmtime::Result<()> {
use crate::p2::bindings::{cli, clocks, random};
let l = linker;
@@ -455,7 +455,7 @@ fn add_proxy_interfaces_nonblocking<T: WasiView>(linker: &mut Linker<T>) -> anyh
/// ```
pub fn add_to_linker_sync<T: WasiView>(
linker: &mut wasmtime::component::Linker<T>,
-) -> anyhow::Result<()> {
+) -> wasmtime::Result<()> {
let options = bindings::sync::LinkOptions::default();
add_to_linker_with_options_sync(linker, &options)
}
@@ -464,7 +464,7 @@ pub fn add_to_linker_sync<T: WasiView>(
pub fn add_to_linker_with_options_sync<T: WasiView>(
linker: &mut wasmtime::component::Linker<T>,
options: &bindings::sync::LinkOptions,
-) -> anyhow::Result<()> {
+) -> wasmtime::Result<()> {
add_nonblocking_to_linker(linker, options)?;
add_sync_wasi_io(linker)?;
@@ -479,7 +479,7 @@ pub fn add_to_linker_with_options_sync<T: WasiView>(
/// [`add_to_linker_proxy_interfaces_sync`].
fn add_sync_wasi_io<T: WasiView>(
linker: &mut wasmtime::component::Linker<T>,
-) -> anyhow::Result<()> {
+) -> wasmtime::Result<()> {
let l = linker;
wasmtime_wasi_io::bindings::wasi::io::error::add_to_linker::<T, HasIo>(l, |t| t.ctx().table)?;
bindings::sync::io::poll::add_to_linker::<T, HasIo>(l, |t| t.ctx().table)?;
@@ -499,7 +499,7 @@ impl HasData for HasIo {
// that's not possible with these two traits in separate crates. For now this
// is some small duplication but if this gets worse over time then we'll want
// to massage this.
-fn add_async_io_to_linker<T: WasiView>(l: &mut Linker<T>) -> anyhow::Result<()> {
+fn add_async_io_to_linker<T: WasiView>(l: &mut Linker<T>) -> wasmtime::Result<()> {
wasmtime_wasi_io::bindings::wasi::io::error::add_to_linker::<T, HasIo>(l, |t| t.ctx().table)?;
wasmtime_wasi_io::bindings::wasi::io::poll::add_to_linker::<T, HasIo>(l, |t| t.ctx().table)?;
wasmtime_wasi_io::bindings::wasi::io::streams::add_to_linker::<T, HasIo>(l, |t| t.ctx().table)?;
diff --git a/crates/wasi/src/p2/pipe.rs b/crates/wasi/src/p2/pipe.rs
index 96b94f40cb..9b5f60303d 100644
--- a/crates/wasi/src/p2/pipe.rs
+++ b/crates/wasi/src/p2/pipe.rs
@@ -7,13 +7,13 @@
//! Some convenience constructors are included for common backing types like `Vec<u8>` and `String`,
//! but the virtual pipes can be instantiated with any `Read` or `Write` type.
//!
-use anyhow::anyhow;
use bytes::Bytes;
use std::pin::{Pin, pin};
use std::sync::{Arc, Mutex};
use std::task::{Context, Poll};
use tokio::io::{self, AsyncRead, AsyncWrite};
use tokio::sync::mpsc;
+use wasmtime::format_err;
use wasmtime_wasi_io::{
poll::Pollable,
streams::{InputStream, OutputStream, StreamError},
@@ -99,7 +99,7 @@ impl OutputStream for MemoryOutputPipe {
fn write(&mut self, bytes: Bytes) -> Result<(), StreamError> {
let mut buf = self.buffer.lock().unwrap();
if bytes.len() > self.capacity - buf.len() {
- return Err(StreamError::Trap(anyhow!(
+ return Err(StreamError::Trap(format_err!(
"write beyond capacity of MemoryOutputPipe"
)));
}
@@ -240,7 +240,7 @@ impl InputStream for AsyncReadStream {
Err(e)
}
Err(TryRecvError::Empty) => Ok(Bytes::new()),
- Err(TryRecvError::Disconnected) => Err(StreamError::Trap(anyhow!(
+ Err(TryRecvError::Disconnected) => Err(StreamError::Trap(format_err!(
"AsyncReadStream sender died - should be impossible"
))),
}
diff --git a/crates/wasi/src/p2/poll.rs b/crates/wasi/src/p2/poll.rs
index 9cbee5f960..e96472e4a7 100644
--- a/crates/wasi/src/p2/poll.rs
+++ b/crates/wasi/src/p2/poll.rs
@@ -1,7 +1,7 @@
use crate::runtime::in_tokio;
use wasmtime_wasi_io::{bindings::wasi::io::poll as async_poll, poll::DynPollable};
-use anyhow::Result;
+use wasmtime::Result;
use wasmtime::component::{Resource, ResourceTable};
impl crate::p2::bindings::sync::io::poll::Host for ResourceTable {
diff --git a/crates/wasi/src/p2/stdio.rs b/crates/wasi/src/p2/stdio.rs
index 3184e00623..ffad53f7dd 100644
--- a/crates/wasi/src/p2/stdio.rs
+++ b/crates/wasi/src/p2/stdio.rs
@@ -13,21 +13,21 @@ pub enum IsATTY {
}
impl stdin::Host for WasiCliCtxView<'_> {
- fn get_stdin(&mut self) -> Result<Resource<streams::DynInputStream>, anyhow::Error> {
+ fn get_stdin(&mut self) -> Result<Resource<streams::DynInputStream>, wasmtime::Error> {
let stream = self.ctx.stdin.p2_stream();
Ok(self.table.push(stream)?)
}
}
impl stdout::Host for WasiCliCtxView<'_> {
- fn get_stdout(&mut self) -> Result<Resource<streams::DynOutputStream>, anyhow::Error> {
+ fn get_stdout(&mut self) -> Result<Resource<streams::DynOutputStream>, wasmtime::Error> {
let stream = self.ctx.stdout.p2_stream();
Ok(self.table.push(stream)?)
}
}
impl stderr::Host for WasiCliCtxView<'_> {
- fn get_stderr(&mut self) -> Result<Resource<streams::DynOutputStream>, anyhow::Error> {
+ fn get_stderr(&mut self) -> Result<Resource<streams::DynOutputStream>, wasmtime::Error> {
let stream = self.ctx.stderr.p2_stream();
Ok(self.table.push(stream)?)
}
@@ -38,20 +38,20 @@ pub struct TerminalOutput;
impl terminal_input::Host for WasiCliCtxView<'_> {}
impl terminal_input::HostTerminalInput for WasiCliCtxView<'_> {
- fn drop(&mut self, r: Resource<TerminalInput>) -> anyhow::Result<()> {
+ fn drop(&mut self, r: Resource<TerminalInput>) -> wasmtime::Result<()> {
self.table.delete(r)?;
Ok(())
}
}
impl terminal_output::Host for WasiCliCtxView<'_> {}
impl terminal_output::HostTerminalOutput for WasiCliCtxView<'_> {
- fn drop(&mut self, r: Resource<TerminalOutput>) -> anyhow::Result<()> {
+ fn drop(&mut self, r: Resource<TerminalOutput>) -> wasmtime::Result<()> {
self.table.delete(r)?;
Ok(())
}
}
impl terminal_stdin::Host for WasiCliCtxView<'_> {
- fn get_terminal_stdin(&mut self) -> anyhow::Result<Option<Resource<TerminalInput>>> {
+ fn get_terminal_stdin(&mut self) -> wasmtime::Result<Option<Resource<TerminalInput>>> {
if self.ctx.stdin.is_terminal() {
let fd = self.table.push(TerminalInput)?;
Ok(Some(fd))
@@ -61,7 +61,7 @@ impl terminal_stdin::Host for WasiCliCtxView<'_> {
}
}
impl terminal_stdout::Host for WasiCliCtxView<'_> {
- fn get_terminal_stdout(&mut self) -> anyhow::Result<Option<Resource<TerminalOutput>>> {
+ fn get_terminal_stdout(&mut self) -> wasmtime::Result<Option<Resource<TerminalOutput>>> {
if self.ctx.stdout.is_terminal() {
let fd = self.table.push(TerminalOutput)?;
Ok(Some(fd))
@@ -71,7 +71,7 @@ impl terminal_stdout::Host for WasiCliCtxView<'_> {
}
}
impl terminal_stderr::Host for WasiCliCtxView<'_> {
- fn get_terminal_stderr(&mut self) -> anyhow::Result<Option<Resource<TerminalOutput>>> {
+ fn get_terminal_stderr(&mut self) -> wasmtime::Result<Option<Resource<TerminalOutput>>> {
if self.ctx.stderr.is_terminal() {
let fd = self.table.push(TerminalOutput)?;
Ok(Some(fd))
diff --git a/crates/wasi/src/p2/tcp.rs b/crates/wasi/src/p2/tcp.rs
index 019c3c6b1f..67edf98ba8 100644
--- a/crates/wasi/src/p2/tcp.rs
+++ b/crates/wasi/src/p2/tcp.rs
@@ -4,7 +4,6 @@ use crate::p2::{
};
use crate::runtime::AbortOnDropJoinHandle;
use crate::sockets::TcpSocket;
-use anyhow::Result;
use io_lifetimes::AsSocketlike;
use rustix::io::Errno;
use std::io;
@@ -12,6 +11,7 @@ use std::mem;
use std::net::Shutdown;
use std::sync::Arc;
use tokio::sync::Mutex;
+use wasmtime::Result;
impl TcpSocket {
pub(crate) fn p2_streams(&mut self) -> SocketResult<(DynInputStream, DynOutputStream)> {
@@ -191,7 +191,7 @@ impl TcpWriter {
WriteState::Ready => {}
WriteState::Closed => return Err(StreamError::Closed),
WriteState::Writing(_) | WriteState::Closing(_) | WriteState::Error(_) => {
- return Err(StreamError::Trap(anyhow::anyhow!(
+ return Err(StreamError::Trap(wasmtime::format_err!(
"unpermitted: must call check_write first"
)));
}
@@ -354,7 +354,7 @@ fn try_lock_for_stream<T>(mutex: &Mutex<T>) -> Result<tokio::sync::MutexGuard<'_
fn try_lock_for_socket<T>(mutex: &Mutex<T>) -> SocketResult<tokio::sync::MutexGuard<'_, T>> {
mutex.try_lock().map_err(|_| {
- SocketError::trap(anyhow::anyhow!(
+ SocketError::trap(wasmtime::format_err!(
"concurrent access to resource not supported"
))
})
diff --git a/crates/wasi/src/p2/write_stream.rs b/crates/wasi/src/p2/write_stream.rs
index e29d343520..658571e3a6 100644
--- a/crates/wasi/src/p2/write_stream.rs
+++ b/crates/wasi/src/p2/write_stream.rs
@@ -1,9 +1,9 @@
use crate::p2::{OutputStream, Pollable, StreamError};
-use anyhow::anyhow;
use bytes::Bytes;
use std::pin::pin;
use std::sync::{Arc, Mutex};
use std::task::{Context, Poll, Waker};
+use wasmtime::format_err;
#[derive(Debug)]
struct WorkerState {
@@ -11,7 +11,7 @@ struct WorkerState {
items: std::collections::VecDeque<Bytes>,
write_budget: usize,
flush_pending: bool,
- error: Option<anyhow::Error>,
+ error: Option<wasmtime::Error>,
write_ready_changed: Option<Waker>,
}
@@ -169,7 +169,7 @@ impl OutputStream for AsyncWriteStream {
let mut state = self.worker.state();
state.check_error()?;
if state.flush_pending {
- return Err(StreamError::Trap(anyhow!(
+ return Err(StreamError::Trap(format_err!(
"write not permitted while flush pending"
)));
}
@@ -178,7 +178,7 @@ impl OutputStream for AsyncWriteStream {
state.write_budget = remaining_budget;
state.items.push_back(bytes);
}
- None => return Err(StreamError::Trap(anyhow!("write exceeded budget"))),
+ None => return Err(StreamError::Trap(format_err!("write exceeded budget"))),
}
drop(state);
self.worker.new_work.notify_one();
diff --git a/crates/wasi/src/p3/cli/host.rs b/crates/wasi/src/p3/cli/host.rs
index 2b413cc1ee..29b4fbc56e 100644
--- a/crates/wasi/src/p3/cli/host.rs
+++ b/crates/wasi/src/p3/cli/host.rs
@@ -7,7 +7,6 @@ use crate::p3::bindings::cli::{
terminal_stdin, terminal_stdout,
};
use crate::p3::cli::{TerminalInput, TerminalOutput};
-use anyhow::{Context as _, anyhow};
use bytes::BytesMut;
use core::pin::Pin;
use core::task::{Context, Poll};
@@ -18,7 +17,7 @@ use wasmtime::component::{
Access, Accessor, Destination, FutureReader, Resource, Source, StreamConsumer, StreamProducer,
StreamReader, StreamResult,
};
-use wasmtime::{AsContextMut as _, StoreContextMut};
+use wasmtime::{AsContextMut as _, StoreContextMut, error::Context as _, format_err};
struct InputStreamProducer {
rx: Pin<Box<dyn AsyncRead + Send + Sync>>,
@@ -206,7 +205,7 @@ impl stdin::HostWithStore for WasiCli {
},
);
let future = FutureReader::new(&mut store, async {
- anyhow::Ok(match result_rx.await {
+ wasmtime::error::Ok(match result_rx.await {
Ok(err) => Err(err),
Err(_) => Ok(()),
})
@@ -287,10 +286,10 @@ impl exit::Host for WasiCliCtxView<'_> {
Ok(()) => 0,
Err(()) => 1,
};
- Err(anyhow!(I32Exit(status)))
+ Err(format_err!(I32Exit(status)))
}
fn exit_with_code(&mut self, status_code: u8) -> wasmtime::Result<()> {
- Err(anyhow!(I32Exit(status_code.into())))
+ Err(format_err!(I32Exit(status_code.into())))
}
}
diff --git a/crates/wasi/src/p3/cli/mod.rs b/crates/wasi/src/p3/cli/mod.rs
index 5989e9c5a6..fb8230d364 100644
--- a/crates/wasi/src/p3/cli/mod.rs
+++ b/crates/wasi/src/p3/cli/mod.rs
@@ -71,7 +71,7 @@ where
pub fn add_to_linker_with_options<T>(
linker: &mut Linker<T>,
exit_options: &exit::LinkOptions,
-) -> anyhow::Result<()>
+) -> wasmtime::Result<()>
where
T: WasiCliView + 'static,
{
diff --git a/crates/wasi/src/p3/filesystem/host.rs b/crates/wasi/src/p3/filesystem/host.rs
index 682fffb752..0c4e0c294b 100644
--- a/crates/wasi/src/p3/filesystem/host.rs
+++ b/crates/wasi/src/p3/filesystem/host.rs
@@ -7,7 +7,6 @@ use crate::p3::bindings::filesystem::types::{
use crate::p3::filesystem::{FilesystemError, FilesystemResult, preopens};
use crate::p3::{DEFAULT_BUFFER_CAPACITY, FallibleIteratorProducer};
use crate::{DirPerms, FilePerms};
-use anyhow::Context as _;
use bytes::BytesMut;
use core::pin::Pin;
use core::task::{Context, Poll, ready};
@@ -22,6 +21,7 @@ use wasmtime::component::{
Access, Accessor, Destination, FutureReader, Resource, ResourceTable, Source, StreamConsumer,
StreamProducer, StreamReader, StreamResult,
};
+use wasmtime::error::Context as _;
fn get_descriptor<'a>(
table: &'a ResourceTable,
@@ -495,7 +495,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem {
return Ok((
StreamReader::new(&mut store, iter::empty()),
FutureReader::new(&mut store, async {
- anyhow::Ok(Err(ErrorCode::NotPermitted))
+ wasmtime::error::Ok(Err(ErrorCode::NotPermitted))
}),
));
}
@@ -636,7 +636,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem {
return Ok((
StreamReader::new(&mut store, iter::empty()),
FutureReader::new(&mut store, async {
- anyhow::Ok(Err(ErrorCode::NotPermitted))
+ wasmtime::error::Ok(Err(ErrorCode::NotPermitted))
}),
));
}
@@ -819,7 +819,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem {
let table = store.get().table;
let fd = get_descriptor(table, &fd)?.clone();
let other = get_descriptor(table, &other)?.clone();
- anyhow::Ok((fd, other))
+ wasmtime::error::Ok((fd, other))
})?;
fd.is_same_object(&other).await
}
diff --git a/crates/wasi/src/p3/sockets/host/types/mod.rs b/crates/wasi/src/p3/sockets/host/types/mod.rs
index 60c152dab4..81fa1b8da2 100644
--- a/crates/wasi/src/p3/sockets/host/types/mod.rs
+++ b/crates/wasi/src/p3/sockets/host/types/mod.rs
@@ -8,7 +8,7 @@ mod tcp;
mod udp;
impl Host for WasiSocketsCtxView<'_> {
- fn convert_error_code(&mut self, error: SocketError) -> anyhow::Result<ErrorCode> {
+ fn convert_error_code(&mut self, error: SocketError) -> wasmtime::Result<ErrorCode> {
error.downcast()
}
}
diff --git a/crates/wasi/src/p3/sockets/host/types/tcp.rs b/crates/wasi/src/p3/sockets/host/types/tcp.rs
index 1eb5a2d72a..2125b62ea5 100644
--- a/crates/wasi/src/p3/sockets/host/types/tcp.rs
+++ b/crates/wasi/src/p3/sockets/host/types/tcp.rs
@@ -6,7 +6,6 @@ use crate::p3::bindings::sockets::types::{
};
use crate::p3::sockets::{SocketError, SocketResult, WasiSockets};
use crate::sockets::{NonInheritedOptions, SocketAddrUse, SocketAddressFamily, WasiSocketsCtxView};
-use anyhow::Context as _;
use bytes::BytesMut;
use core::iter;
use core::pin::Pin;
@@ -21,6 +20,7 @@ use wasmtime::component::{
Access, Accessor, Destination, FutureReader, Resource, ResourceTable, Source, StreamConsumer,
StreamProducer, StreamReader, StreamResult,
};
+use wasmtime::error::Context as _;
use wasmtime::{AsContextMut as _, StoreContextMut};
fn get_socket<'a>(
@@ -331,7 +331,7 @@ impl HostTcpSocketWithStore for WasiSockets {
None => Ok((
StreamReader::new(&mut store, iter::empty()),
FutureReader::new(&mut store, async {
- anyhow::Ok(Err(ErrorCode::InvalidState))
+ wasmtime::error::Ok(Err(ErrorCode::InvalidState))
}),
)),
}
diff --git a/crates/wasi/src/p3/sockets/host/types/udp.rs b/crates/wasi/src/p3/sockets/host/types/udp.rs
index 96982d3088..b37c6bcec0 100644
--- a/crates/wasi/src/p3/sockets/host/types/udp.rs
+++ b/crates/wasi/src/p3/sockets/host/types/udp.rs
@@ -5,9 +5,9 @@ use crate::p3::bindings::sockets::types::{
};
use crate::p3::sockets::{SocketResult, WasiSockets};
use crate::sockets::{MAX_UDP_DATAGRAM_SIZE, SocketAddrUse, UdpSocket, WasiSocketsCtxView};
-use anyhow::Context;
use std::net::SocketAddr;
use wasmtime::component::{Accessor, Resource, ResourceTable};
+use wasmtime::error::Context as _;
fn get_socket<'a>(
table: &'a ResourceTable,
diff --git a/crates/wasi/tests/all/p1.rs b/crates/wasi/tests/all/p1.rs
index 3b95112e43..04cf2a3bc7 100644
--- a/crates/wasi/tests/all/p1.rs
+++ b/crates/wasi/tests/all/p1.rs
@@ -1,7 +1,7 @@
use crate::store::Ctx;
-use anyhow::Result;
use std::path::Path;
use test_programs_artifacts::*;
+use wasmtime::Result;
use wasmtime::{Linker, Module};
use wasmtime_wasi::p1::{WasiP1Ctx, add_to_linker_async};
diff --git a/crates/wasi/tests/all/p2/api.rs b/crates/wasi/tests/all/p2/api.rs
index 659ededcfa..cf3da0fabb 100644
--- a/crates/wasi/tests/all/p2/api.rs
+++ b/crates/wasi/tests/all/p2/api.rs
@@ -1,7 +1,7 @@
-use anyhow::Result;
use std::io::Write;
use std::sync::Mutex;
use std::time::Duration;
+use wasmtime::Result;
use wasmtime::Store;
use wasmtime::component::{Component, Linker, ResourceTable};
use wasmtime_wasi::p2::add_to_linker_async;
@@ -86,7 +86,7 @@ async fn p2_api_time() -> Result<()> {
.wasi_cli_run()
.call_run(&mut store)
.await?
- .map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
+ .map_err(|()| wasmtime::format_err!("command returned with failing exit status"))
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
@@ -108,7 +108,7 @@ async fn p2_api_read_only() -> Result<()> {
.wasi_cli_run()
.call_run(&mut store)
.await?
- .map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
+ .map_err(|()| wasmtime::format_err!("command returned with failing exit status"))
}
#[expect(
diff --git a/crates/wasi/tests/all/p2/async_.rs b/crates/wasi/tests/all/p2/async_.rs
index 737af19077..0e1ec3833f 100644
--- a/crates/wasi/tests/all/p2/async_.rs
+++ b/crates/wasi/tests/all/p2/async_.rs
@@ -1,7 +1,7 @@
use crate::store::{Ctx, MyWasiCtx};
-use anyhow::Result;
use std::path::Path;
use test_programs_artifacts::*;
+use wasmtime::Result;
use wasmtime::component::{Component, Linker};
use wasmtime_wasi::p2::add_to_linker_async;
use wasmtime_wasi::p2::bindings::Command;
@@ -30,7 +30,7 @@ async fn run(path: &str, inherit_stdio: bool) -> Result<()> {
.wasi_cli_run()
.call_run(&mut store)
.await?
- .map_err(|()| anyhow::anyhow!("run returned a failure"))
+ .map_err(|()| wasmtime::format_err!("run returned a failure"))
}
foreach_p1!(assert_test_exists);
diff --git a/crates/wasi/tests/all/p2/sync.rs b/crates/wasi/tests/all/p2/sync.rs
index 9cab6bac86..f00be13698 100644
--- a/crates/wasi/tests/all/p2/sync.rs
+++ b/crates/wasi/tests/all/p2/sync.rs
@@ -30,7 +30,7 @@ fn run(path: &str, inherit_stdio: bool) -> Result<()> {
command
.wasi_cli_run()
.call_run(&mut store)?
- .map_err(|()| anyhow::anyhow!("run returned a failure"))?;
+ .map_err(|()| wasmtime::format_err!("run returned a failure"))?;
}
Ok(())
}
diff --git a/crates/wasi/tests/all/p3/mod.rs b/crates/wasi/tests/all/p3/mod.rs
index 7c9535f0a5..b6cd01e7a5 100644
--- a/crates/wasi/tests/all/p3/mod.rs
+++ b/crates/wasi/tests/all/p3/mod.rs
@@ -1,9 +1,8 @@
use crate::store::{Ctx, MyWasiCtx};
-use anyhow::{Context as _, anyhow};
use std::path::Path;
use test_programs_artifacts::*;
-use wasmtime::Result;
use wasmtime::component::{Component, Linker};
+use wasmtime::{Result, error::Context as _, format_err};
use wasmtime_wasi::p3::bindings::Command;
async fn run(path: &str) -> Result<()> {
@@ -42,128 +41,128 @@ async fn run_allow_blocking_current_thread(
.context("failed to call `wasi:cli/run#run`")?
.context("guest trapped")?
.0
- .map_err(|()| anyhow!("`wasi:cli/run#run` failed"))
+ .map_err(|()| format_err!("`wasi:cli/run#run` failed"))
}
foreach_p3!(assert_test_exists);
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_cli() -> anyhow::Result<()> {
+async fn p3_cli() -> wasmtime::Result<()> {
run(P3_CLI_COMPONENT).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_clocks_sleep() -> anyhow::Result<()> {
+async fn p3_clocks_sleep() -> wasmtime::Result<()> {
run(P3_CLOCKS_SLEEP_COMPONENT).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_filesystem_file_read_write() -> anyhow::Result<()> {
+async fn p3_filesystem_file_read_write() -> wasmtime::Result<()> {
run(P3_FILESYSTEM_FILE_READ_WRITE_COMPONENT).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_filesystem_file_read_write_blocking() -> anyhow::Result<()> {
+async fn p3_filesystem_file_read_write_blocking() -> wasmtime::Result<()> {
run_allow_blocking_current_thread(P3_FILESYSTEM_FILE_READ_WRITE_COMPONENT, true).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_random_imports() -> anyhow::Result<()> {
+async fn p3_random_imports() -> wasmtime::Result<()> {
run(P3_RANDOM_IMPORTS_COMPONENT).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_sockets_ip_name_lookup() -> anyhow::Result<()> {
+async fn p3_sockets_ip_name_lookup() -> wasmtime::Result<()> {
run(P3_SOCKETS_IP_NAME_LOOKUP_COMPONENT).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_sockets_tcp_bind() -> anyhow::Result<()> {
+async fn p3_sockets_tcp_bind() -> wasmtime::Result<()> {
run(P3_SOCKETS_TCP_BIND_COMPONENT).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_sockets_tcp_connect() -> anyhow::Result<()> {
+async fn p3_sockets_tcp_connect() -> wasmtime::Result<()> {
run(P3_SOCKETS_TCP_CONNECT_COMPONENT).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_sockets_tcp_listen() -> anyhow::Result<()> {
+async fn p3_sockets_tcp_listen() -> wasmtime::Result<()> {
run(P3_SOCKETS_TCP_LISTEN_COMPONENT).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_sockets_tcp_sample_application() -> anyhow::Result<()> {
+async fn p3_sockets_tcp_sample_application() -> wasmtime::Result<()> {
run(P3_SOCKETS_TCP_SAMPLE_APPLICATION_COMPONENT).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_sockets_tcp_sockopts() -> anyhow::Result<()> {
+async fn p3_sockets_tcp_sockopts() -> wasmtime::Result<()> {
run(P3_SOCKETS_TCP_SOCKOPTS_COMPONENT).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_sockets_tcp_states() -> anyhow::Result<()> {
+async fn p3_sockets_tcp_states() -> wasmtime::Result<()> {
run(P3_SOCKETS_TCP_STATES_COMPONENT).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_sockets_tcp_streams() -> anyhow::Result<()> {
+async fn p3_sockets_tcp_streams() -> wasmtime::Result<()> {
run(P3_SOCKETS_TCP_STREAMS_COMPONENT).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_sockets_udp_bind() -> anyhow::Result<()> {
+async fn p3_sockets_udp_bind() -> wasmtime::Result<()> {
run(P3_SOCKETS_UDP_BIND_COMPONENT).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_sockets_udp_connect() -> anyhow::Result<()> {
+async fn p3_sockets_udp_connect() -> wasmtime::Result<()> {
run(P3_SOCKETS_UDP_CONNECT_COMPONENT).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_sockets_udp_receive() -> anyhow::Result<()> {
+async fn p3_sockets_udp_receive() -> wasmtime::Result<()> {
run(P3_SOCKETS_UDP_RECEIVE_COMPONENT).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_sockets_udp_sample_application() -> anyhow::Result<()> {
+async fn p3_sockets_udp_sample_application() -> wasmtime::Result<()> {
run(P3_SOCKETS_UDP_SAMPLE_APPLICATION_COMPONENT).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_sockets_udp_send() -> anyhow::Result<()> {
+async fn p3_sockets_udp_send() -> wasmtime::Result<()> {
run(P3_SOCKETS_UDP_SEND_COMPONENT).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_sockets_udp_sockopts() -> anyhow::Result<()> {
+async fn p3_sockets_udp_sockopts() -> wasmtime::Result<()> {
run(P3_SOCKETS_UDP_SOCKOPTS_COMPONENT).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_sockets_udp_states() -> anyhow::Result<()> {
+async fn p3_sockets_udp_states() -> wasmtime::Result<()> {
run(P3_SOCKETS_UDP_STATES_COMPONENT).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_readdir() -> anyhow::Result<()> {
+async fn p3_readdir() -> wasmtime::Result<()> {
run(P3_READDIR_COMPONENT).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_readdir_blocking() -> anyhow::Result<()> {
+async fn p3_readdir_blocking() -> wasmtime::Result<()> {
run_allow_blocking_current_thread(P3_READDIR_COMPONENT, true).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_file_write() -> anyhow::Result<()> {
+async fn p3_file_write() -> wasmtime::Result<()> {
run(P3_FILE_WRITE_COMPONENT).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
-async fn p3_file_write_blocking() -> anyhow::Result<()> {
+async fn p3_file_write_blocking() -> wasmtime::Result<()> {
run_allow_blocking_current_thread(P3_FILE_WRITE_COMPONENT, true).await
}
diff --git a/crates/wasi/tests/all/store.rs b/crates/wasi/tests/all/store.rs
index f96b7cb561..219b77ec84 100644
--- a/crates/wasi/tests/all/store.rs
+++ b/crates/wasi/tests/all/store.rs
@@ -1,5 +1,5 @@
-use anyhow::Result;
use tempfile::TempDir;
+use wasmtime::Result;
use wasmtime::component::ResourceTable;
use wasmtime::{Engine, Store};
use wasmtime_wasi::{