A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Migrate wasi-io to `wasmtime::error` (#12290)
Nick Fitzgerald747654b2f314
diff --git a/Cargo.lock b/Cargo.lockindex 96d00d7150..f53774533e 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -5141,7 +5141,6 @@ dependencies = [name = "wasmtime-wasi-io"version = "42.0.0"dependencies = [- "anyhow","async-trait","bytes","futures",@@ -5152,7 +5151,6 @@ dependencies = [name = "wasmtime-wasi-keyvalue"version = "42.0.0"dependencies = [- "anyhow","test-programs-artifacts","tokio","wasmtime",diff --git a/crates/wasi-io/Cargo.toml b/crates/wasi-io/Cargo.tomlindex 70e379ea6a..56530c6fd3 100644--- a/crates/wasi-io/Cargo.toml+++ b/crates/wasi-io/Cargo.toml@@ -15,7 +15,6 @@ workspace = true[dependencies]wasmtime = { workspace = true, features = ["component-model", "async", "runtime"] }-anyhow = { workspace = true }bytes = { workspace = true }async-trait = { workspace = true }futures = { workspace = true }@@ -24,7 +23,5 @@ futures = { workspace = true }default = [ "std" ]std = ["bytes/std",- "anyhow/std","wasmtime/std",]-diff --git a/crates/wasi-io/src/impls.rs b/crates/wasi-io/src/impls.rsindex fe366e59b5..cd3a1a705e 100644--- a/crates/wasi-io/src/impls.rs+++ b/crates/wasi-io/src/impls.rs@@ -4,18 +4,18 @@ use crate::streams::{DynInputStream, DynOutputStream, StreamError, StreamResult}use alloc::collections::BTreeMap;use alloc::string::String;use alloc::vec::Vec;-use anyhow::{Result, anyhow};use core::future::Future;use core::pin::Pin;use core::task::{Context, Poll};use wasmtime::component::{Resource, ResourceTable};+use wasmtime::{Result, format_err};impl poll::Host for ResourceTable {async fn poll(&mut self, pollables: Vec<Resource<DynPollable>>) -> Result<Vec<u32>> {type ReadylistIndex = u32;if pollables.is_empty() {- return Err(anyhow!("empty poll list"));+ return Err(format_err!("empty poll list"));}let mut table_futures: BTreeMap<u32, (MakeFuture, Vec<ReadylistIndex>)> = BTreeMap::new();diff --git a/crates/wasi-io/src/poll.rs b/crates/wasi-io/src/poll.rsindex 1173ec2bb2..7187db2a03 100644--- a/crates/wasi-io/src/poll.rs+++ b/crates/wasi-io/src/poll.rs@@ -1,8 +1,8 @@use alloc::boxed::Box;-use anyhow::Result;use core::any::Any;use core::future::Future;use core::pin::Pin;+use wasmtime::Result;use wasmtime::component::{Resource, ResourceTable};pub type DynFuture<'a> = Pin<Box<dyn Future<Output = ()> + Send + 'a>>;diff --git a/crates/wasi-io/src/streams.rs b/crates/wasi-io/src/streams.rsindex bebd20a6a9..9b630a7e8e 100644--- a/crates/wasi-io/src/streams.rs+++ b/crates/wasi-io/src/streams.rs@@ -1,7 +1,7 @@use crate::poll::Pollable;use alloc::boxed::Box;-use anyhow::Result;use bytes::Bytes;+use wasmtime::Result;/// `Pollable::ready()` for `InputStream` and `OutputStream` may return/// prematurely due to `io::ErrorKind::WouldBlock`.@@ -76,22 +76,22 @@ pub trait InputStream: Pollable {/// Representation of the `error` resource type in the `wasi:io/error`/// interface.///-/// This is currently `anyhow::Error` to retain full type information for+/// This is currently `wasmtime::Error` to retain full type information for/// errors.-pub type Error = anyhow::Error;+pub type Error = wasmtime::Error;pub type StreamResult<T> = Result<T, StreamError>;#[derive(Debug)]pub enum StreamError {Closed,- LastOperationFailed(anyhow::Error),- Trap(anyhow::Error),+ LastOperationFailed(wasmtime::Error),+ Trap(wasmtime::Error),}impl StreamError {pub fn trap(msg: &str) -> StreamError {- StreamError::Trap(anyhow::anyhow!("{msg}"))+ StreamError::Trap(wasmtime::format_err!("{msg}"))}}diff --git a/crates/wasi-keyvalue/Cargo.toml b/crates/wasi-keyvalue/Cargo.tomlindex 860e37a79d..686e69910f 100644--- a/crates/wasi-keyvalue/Cargo.toml+++ b/crates/wasi-keyvalue/Cargo.toml@@ -12,7 +12,6 @@ description = "Wasmtime implementation of the wasi-keyvalue API"workspace = true[dependencies]-anyhow = { workspace = true }wasmtime = { workspace = true, features = ["runtime", "component-model", "std"] }[dev-dependencies]diff --git a/crates/wasi-keyvalue/src/lib.rs b/crates/wasi-keyvalue/src/lib.rsindex 9e4e95655d..764287e2d6 100644--- a/crates/wasi-keyvalue/src/lib.rs+++ b/crates/wasi-keyvalue/src/lib.rs@@ -81,8 +81,8 @@ mod generated {}use self::generated::wasi::keyvalue;-use anyhow::Result;use std::collections::HashMap;+use wasmtime::Result;use wasmtime::component::{HasData, Resource, ResourceTable, ResourceTableError};#[doc(hidden)]diff --git a/crates/wasi-keyvalue/tests/main.rs b/crates/wasi-keyvalue/tests/main.rsindex a9529441d9..21d7ad4d63 100644--- a/crates/wasi-keyvalue/tests/main.rs+++ b/crates/wasi-keyvalue/tests/main.rs@@ -1,8 +1,8 @@-use anyhow::{Result, anyhow};use test_programs_artifacts::{KEYVALUE_MAIN_COMPONENT, foreach_keyvalue};use wasmtime::{- Store,+ Result, Store,component::{Component, Linker, ResourceTable},+ format_err,};use wasmtime_wasi::{WasiCtx, WasiCtxView, WasiView, p2::bindings::Command};use wasmtime_wasi_keyvalue::{WasiKeyValue, WasiKeyValueCtx, WasiKeyValueCtxBuilder};@@ -40,7 +40,7 @@ async fn run_wasi(path: &str, ctx: Ctx) -> Result<()> {.wasi_cli_run().call_run(&mut store).await?- .map_err(|()| anyhow!("command returned with failing exit status"))+ .map_err(|()| format_err!("command returned with failing exit status"))}macro_rules! assert_test_exists {