Skip to content

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

Migrate component model async tests to `wasmtime::error` (#12270)

Nick Fitzgerald799534a9a84e
diff --git a/Cargo.lock b/Cargo.lock
index 97cc7e7923..84e7b108b8 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -630,7 +630,6 @@ checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
name = "component-async-tests"
version = "0.0.0"
dependencies = [
- "anyhow",
"bytes",
"env_logger 0.11.5",
"futures",
diff --git a/crates/misc/component-async-tests/Cargo.toml b/crates/misc/component-async-tests/Cargo.toml
index caa0b39f55..b70d5691af 100644
--- a/crates/misc/component-async-tests/Cargo.toml
+++ b/crates/misc/component-async-tests/Cargo.toml
@@ -11,7 +11,6 @@ publish = false
workspace = true
[dependencies]
-anyhow = { workspace = true }
futures = { workspace = true, features = ['async-await'] }
env_logger = { workspace = true }
tempfile = { workspace = true }
diff --git a/crates/misc/component-async-tests/src/borrowing_host.rs b/crates/misc/component-async-tests/src/borrowing_host.rs
index 9029263478..a26cab7558 100644
--- a/crates/misc/component-async-tests/src/borrowing_host.rs
+++ b/crates/misc/component-async-tests/src/borrowing_host.rs
@@ -1,4 +1,4 @@
-use anyhow::Result;
+use wasmtime::Result;
use wasmtime::component::Resource;
use super::Ctx;
diff --git a/crates/misc/component-async-tests/src/resource_stream.rs b/crates/misc/component-async-tests/src/resource_stream.rs
index eface6d49b..494502488d 100644
--- a/crates/misc/component-async-tests/src/resource_stream.rs
+++ b/crates/misc/component-async-tests/src/resource_stream.rs
@@ -1,6 +1,6 @@
use crate::util::PipeProducer;
-use anyhow::Result;
use futures::channel::mpsc;
+use wasmtime::Result;
use wasmtime::component::{Accessor, Resource, StreamReader};
use super::Ctx;
diff --git a/crates/misc/component-async-tests/src/round_trip_many.rs b/crates/misc/component-async-tests/src/round_trip_many.rs
index 188c506a90..6f9cf5f146 100644
--- a/crates/misc/component-async-tests/src/round_trip_many.rs
+++ b/crates/misc/component-async-tests/src/round_trip_many.rs
@@ -1,6 +1,6 @@
use super::Ctx;
-use anyhow::Result;
use std::time::Duration;
+use wasmtime::Result;
use wasmtime::component::Accessor;
pub mod bindings {
diff --git a/crates/misc/component-async-tests/src/util.rs b/crates/misc/component-async-tests/src/util.rs
index 0d9ddcc9fe..2fb1dbf4f7 100644
--- a/crates/misc/component-async-tests/src/util.rs
+++ b/crates/misc/component-async-tests/src/util.rs
@@ -1,4 +1,3 @@
-use anyhow::Result;
use futures::{Sink, Stream, channel::oneshot};
use std::{
marker::PhantomData,
@@ -6,6 +5,7 @@ use std::{
task::{Context, Poll},
thread,
};
+use wasmtime::Result;
use wasmtime::{
StoreContextMut,
component::{
diff --git a/crates/misc/component-async-tests/tests/scenario/backpressure.rs b/crates/misc/component-async-tests/tests/scenario/backpressure.rs
index fed3526fa7..21f18cdf27 100644
--- a/crates/misc/component-async-tests/tests/scenario/backpressure.rs
+++ b/crates/misc/component-async-tests/tests/scenario/backpressure.rs
@@ -1,4 +1,4 @@
-use anyhow::Result;
+use wasmtime::Result;
use super::util::test_run;
diff --git a/crates/misc/component-async-tests/tests/scenario/borrowing.rs b/crates/misc/component-async-tests/tests/scenario/borrowing.rs
index 698091a3d5..6541205970 100644
--- a/crates/misc/component-async-tests/tests/scenario/borrowing.rs
+++ b/crates/misc/component-async-tests/tests/scenario/borrowing.rs
@@ -3,8 +3,8 @@ use std::sync::{Arc, Mutex};
use std::time::Duration;
use super::util::{config, make_component};
-use anyhow::Result;
use futures::stream::{FuturesUnordered, TryStreamExt};
+use wasmtime::Result;
use wasmtime::component::{Linker, ResourceTable};
use wasmtime::{Engine, Store};
use wasmtime_wasi::WasiCtxBuilder;
@@ -120,7 +120,7 @@ pub async fn test_run_bool(components: &[&str], v: bool) -> Result<()> {
// continue
}
- anyhow::Ok(())
+ wasmtime::error::Ok(())
})
.await?
}
diff --git a/crates/misc/component-async-tests/tests/scenario/common.rs b/crates/misc/component-async-tests/tests/scenario/common.rs
index 669097ce9d..13ec2d169c 100644
--- a/crates/misc/component-async-tests/tests/scenario/common.rs
+++ b/crates/misc/component-async-tests/tests/scenario/common.rs
@@ -1,7 +1,7 @@
use std::sync::{Arc, Mutex, Once};
use std::time::Duration;
-use anyhow::Result;
+use wasmtime::Result;
use tokio::fs;
use wasm_compose::composer::ComponentComposer;
use wasmtime::component::{Component, Linker, PromisesUnordered, ResourceTable};
diff --git a/crates/misc/component-async-tests/tests/scenario/error_context.rs b/crates/misc/component-async-tests/tests/scenario/error_context.rs
index 8dfe18798e..1bce3bf215 100644
--- a/crates/misc/component-async-tests/tests/scenario/error_context.rs
+++ b/crates/misc/component-async-tests/tests/scenario/error_context.rs
@@ -1,4 +1,4 @@
-use anyhow::Result;
+use wasmtime::Result;
use super::util::test_run;
diff --git a/crates/misc/component-async-tests/tests/scenario/post_return.rs b/crates/misc/component-async-tests/tests/scenario/post_return.rs
index 6a3bf6ef2c..18cd945f79 100644
--- a/crates/misc/component-async-tests/tests/scenario/post_return.rs
+++ b/crates/misc/component-async-tests/tests/scenario/post_return.rs
@@ -1,6 +1,5 @@
use super::util::test_run;
use crate::scenario::util::{config, make_component};
-use anyhow::Result;
use component_async_tests::util;
use component_async_tests::{Ctx, sleep};
use std::future;
@@ -8,6 +7,7 @@ use std::pin::pin;
use std::sync::{Arc, Mutex};
use std::task::Poll;
use std::time::Duration;
+use wasmtime::Result;
use wasmtime::component::{Accessor, Linker, ResourceTable};
use wasmtime::{AsContextMut, Engine, Store, StoreContextMut};
use wasmtime_wasi::WasiCtxBuilder;
@@ -90,7 +90,7 @@ async fn test_sleep_post_return(components: &[&str]) -> Result<()> {
// The function has returned, now we wait for it (and any subtasks
// it may have spawned) to exit.
exit.block(accessor).await;
- anyhow::Ok(())
+ wasmtime::error::Ok(())
}
async fn run(
@@ -110,7 +110,7 @@ async fn test_sleep_post_return(components: &[&str]) -> Result<()> {
run_with(accessor, guest).await?;
- anyhow::Ok(())
+ wasmtime::error::Ok(())
})
.await?
}
diff --git a/crates/misc/component-async-tests/tests/scenario/read_resource_stream.rs b/crates/misc/component-async-tests/tests/scenario/read_resource_stream.rs
index 871f1e5d05..1a23f7b1be 100644
--- a/crates/misc/component-async-tests/tests/scenario/read_resource_stream.rs
+++ b/crates/misc/component-async-tests/tests/scenario/read_resource_stream.rs
@@ -1,5 +1,5 @@
use super::util::test_run;
-use anyhow::Result;
+use wasmtime::Result;
#[tokio::test]
pub async fn async_read_resource_stream() -> Result<()> {
diff --git a/crates/misc/component-async-tests/tests/scenario/round_trip.rs b/crates/misc/component-async-tests/tests/scenario/round_trip.rs
index 6800b5af13..b2a14c30f1 100644
--- a/crates/misc/component-async-tests/tests/scenario/round_trip.rs
+++ b/crates/misc/component-async-tests/tests/scenario/round_trip.rs
@@ -5,7 +5,6 @@ use std::sync::{
use std::time::Duration;
use super::util::{config, make_component};
-use anyhow::{Result, anyhow};
use component_async_tests::Ctx;
use component_async_tests::util::sleep;
use futures::{
@@ -14,7 +13,7 @@ use futures::{
stream::{FuturesUnordered, TryStreamExt},
};
use wasmtime::component::{Accessor, AccessorTask, HasSelf, Instance, Linker, ResourceTable, Val};
-use wasmtime::{Engine, Store};
+use wasmtime::{Engine, Result, Store, format_err};
use wasmtime_wasi::WasiCtxBuilder;
#[tokio::test]
@@ -378,13 +377,13 @@ pub async fn test_round_trip(
let instance = linker.instantiate_async(&mut store, &component).await?;
let baz_instance = instance
.get_export_index(&mut store, None, "local:local/baz")
- .ok_or_else(|| anyhow!("can't find `local:local/baz` in instance"))?;
+ .ok_or_else(|| format_err!("can't find `local:local/baz` in instance"))?;
let foo_function = instance
.get_export_index(&mut store, Some(&baz_instance), "foo")
- .ok_or_else(|| anyhow!("can't find `foo` in instance"))?;
+ .ok_or_else(|| format_err!("can't find `foo` in instance"))?;
let foo_function = instance
.get_func(&mut store, foo_function)
- .ok_or_else(|| anyhow!("can't find `foo` in instance"))?;
+ .ok_or_else(|| format_err!("can't find `foo` in instance"))?;
if call_style == 3 || !cfg!(miri) {
store
@@ -402,7 +401,7 @@ pub async fn test_round_trip(
&mut results,
)
.await?;
- anyhow::Ok((results, output))
+ wasmtime::error::Ok((results, output))
});
}
@@ -412,7 +411,7 @@ pub async fn test_round_trip(
};
assert_eq!(expected, actual);
}
- anyhow::Ok(())
+ wasmtime::error::Ok(())
})
.await??;
diff --git a/crates/misc/component-async-tests/tests/scenario/round_trip_direct.rs b/crates/misc/component-async-tests/tests/scenario/round_trip_direct.rs
index e8eda15e68..e35ae6345e 100644
--- a/crates/misc/component-async-tests/tests/scenario/round_trip_direct.rs
+++ b/crates/misc/component-async-tests/tests/scenario/round_trip_direct.rs
@@ -2,12 +2,11 @@ use std::sync::{Arc, Mutex};
use std::time::Duration;
use super::util::{config, make_component};
-use anyhow::{Result, anyhow};
use component_async_tests::Ctx;
use component_async_tests::util::sleep;
use futures::stream::{FuturesUnordered, TryStreamExt};
use wasmtime::component::{Linker, ResourceTable, Val};
-use wasmtime::{Engine, Store};
+use wasmtime::{Engine, Result, Store, format_err};
use wasmtime_wasi::WasiCtxBuilder;
#[tokio::test]
@@ -81,7 +80,7 @@ async fn test_round_trip_direct(
assert_eq!(expected_output, value);
}
- anyhow::Ok(())
+ wasmtime::error::Ok(())
}
})
.await??;
@@ -110,10 +109,10 @@ async fn test_round_trip_direct(
let instance = linker.instantiate_async(&mut store, &component).await?;
let foo_function = instance
.get_export_index(&mut store, None, "foo")
- .ok_or_else(|| anyhow!("can't find `foo` in instance"))?;
+ .ok_or_else(|| format_err!("can't find `foo` in instance"))?;
let foo_function = instance
.get_func(&mut store, foo_function)
- .ok_or_else(|| anyhow!("can't find `foo` in instance"))?;
+ .ok_or_else(|| format_err!("can't find `foo` in instance"))?;
// Start three concurrent calls and then join them all:
store
@@ -125,7 +124,7 @@ async fn test_round_trip_direct(
foo_function
.call_concurrent(store, &[Val::String(input.to_owned())], &mut results)
.await?;
- anyhow::Ok(results)
+ wasmtime::error::Ok(results)
});
}
diff --git a/crates/misc/component-async-tests/tests/scenario/round_trip_many.rs b/crates/misc/component-async-tests/tests/scenario/round_trip_many.rs
index 3c1543026f..4a61f58524 100644
--- a/crates/misc/component-async-tests/tests/scenario/round_trip_many.rs
+++ b/crates/misc/component-async-tests/tests/scenario/round_trip_many.rs
@@ -6,7 +6,6 @@ use std::sync::{
use std::time::Duration;
use super::util::{config, make_component};
-use anyhow::{Result, anyhow};
use component_async_tests::Ctx;
use component_async_tests::util::sleep;
use futures::{
@@ -14,7 +13,7 @@ use futures::{
stream::{FuturesUnordered, TryStreamExt},
};
use wasmtime::component::{Linker, ResourceTable, Val};
-use wasmtime::{Engine, Store};
+use wasmtime::{Engine, Result, Store, format_err};
use wasmtime_wasi::WasiCtxBuilder;
#[tokio::test]
@@ -288,7 +287,7 @@ async fn test_round_trip_many(
);
}
- anyhow::Ok(())
+ wasmtime::error::Ok(())
}
})
.await??;
@@ -362,13 +361,13 @@ async fn test_round_trip_many(
let instance = linker.instantiate_async(&mut store, &component).await?;
let baz_instance = instance
.get_export_index(&mut store, None, "local:local/many")
- .ok_or_else(|| anyhow!("can't find `local:local/many` in instance"))?;
+ .ok_or_else(|| format_err!("can't find `local:local/many` in instance"))?;
let foo_function = instance
.get_export_index(&mut store, Some(&baz_instance), "foo")
- .ok_or_else(|| anyhow!("can't find `foo` in instance"))?;
+ .ok_or_else(|| format_err!("can't find `foo` in instance"))?;
let foo_function = instance
.get_func(&mut store, foo_function)
- .ok_or_else(|| anyhow!("can't find `foo` in instance"))?;
+ .ok_or_else(|| format_err!("can't find `foo` in instance"))?;
let make = |input: &str| {
let stuff = Val::Record(vec![
@@ -402,7 +401,7 @@ async fn test_round_trip_many(
foo_function
.call_concurrent(store, &make(input), &mut result)
.await?;
- anyhow::Ok((result, output))
+ wasmtime::error::Ok((result, output))
});
}
diff --git a/crates/misc/component-async-tests/tests/scenario/streams.rs b/crates/misc/component-async-tests/tests/scenario/streams.rs
index 267403a563..9f9175e57b 100644
--- a/crates/misc/component-async-tests/tests/scenario/streams.rs
+++ b/crates/misc/component-async-tests/tests/scenario/streams.rs
@@ -1,6 +1,5 @@
use {
super::util::{config, make_component},
- anyhow::Result,
component_async_tests::{
Ctx, closed_streams,
util::{OneshotConsumer, OneshotProducer, PipeConsumer, PipeProducer},
@@ -19,7 +18,7 @@ use {
time::Duration,
},
wasmtime::{
- Engine, Store, StoreContextMut,
+ Engine, Result, Store, StoreContextMut,
component::{
Destination, FutureReader, Lift, Linker, ResourceTable, Source, StreamConsumer,
StreamProducer, StreamReader, StreamResult, VecBuffer,
@@ -164,7 +163,7 @@ pub async fn async_closed_streams() -> Result<()> {
input_tx.send(value).await?;
}
drop(input_tx);
- anyhow::Ok(())
+ wasmtime::error::Ok(())
},
async {
for &value in &values {
@@ -193,7 +192,7 @@ pub async fn async_closed_streams() -> Result<()> {
.run_concurrent(async |_| {
_ = input_tx.send(value);
assert_eq!(value, output_rx.await?);
- anyhow::Ok(())
+ wasmtime::error::Ok(())
})
.await??;
}
@@ -464,7 +463,7 @@ async fn test_async_short_reads(delay: bool) -> Result<()> {
.collect::<Vec<_>>()
);
- anyhow::Ok(())
+ wasmtime::error::Ok(())
})
.await?
}
diff --git a/crates/misc/component-async-tests/tests/scenario/transmit.rs b/crates/misc/component-async-tests/tests/scenario/transmit.rs
index 16c6fb0a9f..dc1f09f2b8 100644
--- a/crates/misc/component-async-tests/tests/scenario/transmit.rs
+++ b/crates/misc/component-async-tests/tests/scenario/transmit.rs
@@ -5,7 +5,6 @@ use std::task::{self, Context, Poll};
use std::time::Duration;
use super::util::{config, make_component, test_run, test_run_with_count};
-use anyhow::{Result, anyhow};
use cancel::exports::local::local::cancel::Mode;
use component_async_tests::transmit::bindings::exports::local::local::transmit::Control;
use component_async_tests::util::{OneshotConsumer, OneshotProducer, PipeConsumer, PipeProducer};
@@ -20,7 +19,7 @@ use wasmtime::component::{
Instance, Linker, ResourceTable, Source, StreamConsumer, StreamProducer, StreamReader,
StreamResult, Val,
};
-use wasmtime::{AsContextMut, Engine, Store, StoreContextMut};
+use wasmtime::{AsContextMut, Engine, Result, Store, StoreContextMut, format_err};
use wasmtime_wasi::WasiCtxBuilder;
struct BufferStreamProducer {
@@ -648,13 +647,13 @@ impl TransmitTest for DynamicTransmitTest {
let exchange_function = accessor.with(|mut store| {
let transmit_instance = instance
.get_export_index(store.as_context_mut(), None, "local:local/transmit")
- .ok_or_else(|| anyhow!("can't find `local:local/transmit` in instance"))?;
+ .ok_or_else(|| format_err!("can't find `local:local/transmit` in instance"))?;
let exchange_function = instance
.get_export_index(store.as_context_mut(), Some(&transmit_instance), "exchange")
- .ok_or_else(|| anyhow!("can't find `exchange` in instance"))?;
+ .ok_or_else(|| format_err!("can't find `exchange` in instance"))?;
instance
.get_func(store.as_context_mut(), exchange_function)
- .ok_or_else(|| anyhow!("can't find `exchange` in instance"))
+ .ok_or_else(|| format_err!("can't find `exchange` in instance"))
})?;
let mut results = vec![Val::Bool(false)];
@@ -822,7 +821,7 @@ async fn test_transmit_with<Test: TransmitTest + 'static>(component: &str) -> Re
&mut store,
OneshotConsumer::new(callee_future1_tx.take().unwrap()),
);
- anyhow::Ok(())
+ wasmtime::error::Ok(())
})?;
}
Event::ControlWriteA(mut control_tx) => {
@@ -892,7 +891,7 @@ async fn test_transmit_with<Test: TransmitTest + 'static>(component: &str) -> Re
assert!(complete);
- anyhow::Ok(())
+ wasmtime::error::Ok(())
})
.await??;
Ok(())
diff --git a/crates/misc/component-async-tests/tests/scenario/unit_stream.rs b/crates/misc/component-async-tests/tests/scenario/unit_stream.rs
index ca4c28b7c6..388ea1b746 100644
--- a/crates/misc/component-async-tests/tests/scenario/unit_stream.rs
+++ b/crates/misc/component-async-tests/tests/scenario/unit_stream.rs
@@ -1,4 +1,4 @@
-use anyhow::Result;
+use wasmtime::Result;
use super::util::test_run_with_count;
diff --git a/crates/misc/component-async-tests/tests/scenario/util.rs b/crates/misc/component-async-tests/tests/scenario/util.rs
index d89bc94099..f5bf8498ca 100644
--- a/crates/misc/component-async-tests/tests/scenario/util.rs
+++ b/crates/misc/component-async-tests/tests/scenario/util.rs
@@ -5,14 +5,13 @@ use std::path::Path;
use std::sync::{Arc, LazyLock, Once};
use std::time::Duration;
-use anyhow::{Result, anyhow, bail};
use component_async_tests::{Ctx, sleep};
use futures::stream::{FuturesUnordered, TryStreamExt};
use tokio::fs;
use tokio::sync::Mutex;
use wasm_compose::composer::ComponentComposer;
use wasmtime::component::{Component, Linker, ResourceTable};
-use wasmtime::{Config, Engine, Store};
+use wasmtime::{Config, Engine, Result, Store, bail, format_err};
use wasmtime_wasi::WasiCtxBuilder;
pub fn init_logger() {
@@ -69,7 +68,7 @@ async fn compose(a: &[u8], b: &[u8]) -> Result<Vec<u8>> {
pub async fn make_component(engine: &Engine, components: &[&str]) -> Result<Component> {
fn cwasm_name(components: &[&str]) -> Result<String> {
if components.is_empty() {
- Err(anyhow!("expected at least one path"))
+ Err(format_err!("expected at least one path"))
} else {
let names = components
.iter()
@@ -78,7 +77,7 @@ pub async fn make_component(engine: &Engine, components: &[&str]) -> Result<Comp
if let Some(name) = path.file_name() {
Ok(name)
} else {
- Err(anyhow!(
+ Err(format_err!(
"expected path with at least two components; got: {}",
path.display()
))
@@ -108,7 +107,7 @@ pub async fn make_component(engine: &Engine, components: &[&str]) -> Result<Comp
}
}
engine.precompile_component(
- &composed.ok_or_else(|| anyhow!("expected at least one component"))?,
+ &composed.ok_or_else(|| format_err!("expected at least one component"))?,
)
}
@@ -233,7 +232,7 @@ pub async fn test_run_with_count(components: &[&str], count: usize) -> Result<()
while let Some(()) = futures.try_next().await? {
// continue
}
- anyhow::Ok(())
+ wasmtime::error::Ok(())
})
.await??;
diff --git a/crates/misc/component-async-tests/tests/scenario/yield_.rs b/crates/misc/component-async-tests/tests/scenario/yield_.rs
index 4f9577e53f..70de715ea3 100644
--- a/crates/misc/component-async-tests/tests/scenario/yield_.rs
+++ b/crates/misc/component-async-tests/tests/scenario/yield_.rs
@@ -1,4 +1,4 @@
-use anyhow::Result;
+use wasmtime::Result;
use super::util::test_run;