Skip to content

Commit

Permalink
Merge pull request #398 from bytecodealliance/remove-anyhow
Browse files Browse the repository at this point in the history
  • Loading branch information
jbourassa authored Nov 4, 2024
2 parents e9ee5ca + 39ded32 commit 70f5075
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 15 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion ext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ wasmtime = { version = "=26.0.0", features = ["memory-protection-keys"] }
wasmtime-wasi = "=26.0.0"
wasi-common = "=26.0.0"
cap-std = "3.1.0"
anyhow = "*" # Use whatever Wasmtime uses
wat = "1.218.0"
tokio = { version = "1.40.0", features = [
"rt",
Expand Down
6 changes: 3 additions & 3 deletions ext/src/ruby_api/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ macro_rules! caller_error {
($store:expr, $caller:expr, $error:expr) => {{
$store.set_last_error($error);
$caller.expire();
Err(anyhow::anyhow!(""))
Err(wasmtime::Error::msg(""))
}};
}

Expand All @@ -257,7 +257,7 @@ macro_rules! result_error {
pub fn make_func_closure(
ty: &wasmtime::FuncType,
callable: Opaque<Proc>,
) -> impl Fn(CallerImpl<'_, StoreData>, &[Val], &mut [Val]) -> anyhow::Result<()> + Send + Sync + 'static
) -> impl Fn(CallerImpl<'_, StoreData>, &[Val], &mut [Val]) -> wasmtime::Result<()> + Send + Sync + 'static
{
let ty = ty.to_owned();

Expand All @@ -276,7 +276,7 @@ pub fn make_func_closure(
for (i, param) in params.iter().enumerate() {
let rparam = param
.to_ruby_value(&store_context)
.map_err(|e| anyhow::anyhow!(format!("invalid argument at index {i}: {e}")))?;
.map_err(|e| wasmtime::Error::msg(format!("invalid argument at index {i}: {e}")))?;
rparams.push(rparam).unwrap();
}

Expand Down
10 changes: 5 additions & 5 deletions ext/src/ruby_api/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ impl<'a> StoreContextValue<'a> {
};
}

pub fn handle_wasm_error(&self, error: anyhow::Error) -> Error {
pub fn handle_wasm_error(&self, error: wasmtime::Error) -> Error {
if let Ok(Some(error)) = self.take_last_error() {
error
} else if let Some(exit) = error.downcast_ref::<I32Exit>() {
Expand Down Expand Up @@ -431,7 +431,7 @@ impl ResourceLimiter for TrackingResourceLimiter {
current: usize,
desired: usize,
maximum: Option<usize>,
) -> anyhow::Result<bool> {
) -> wasmtime::Result<bool> {
let res = self.inner.memory_growing(current, desired, maximum);

// Update max_linear_memory_consumed
Expand All @@ -457,16 +457,16 @@ impl ResourceLimiter for TrackingResourceLimiter {
current: usize,
desired: usize,
maximum: Option<usize>,
) -> anyhow::Result<bool> {
) -> wasmtime::Result<bool> {
self.inner.table_growing(current, desired, maximum)
}

fn memory_grow_failed(&mut self, error: anyhow::Error) -> anyhow::Result<()> {
fn memory_grow_failed(&mut self, error: wasmtime::Error) -> wasmtime::Result<()> {
self.linear_memory_limit_hit = true;
self.inner.memory_grow_failed(error)
}

fn table_grow_failed(&mut self, error: anyhow::Error) -> anyhow::Result<()> {
fn table_grow_failed(&mut self, error: wasmtime::Error) -> wasmtime::Result<()> {
self.inner.table_grow_failed(error)
}

Expand Down
2 changes: 0 additions & 2 deletions ext/src/ruby_api/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use super::{
store::{Store, StoreContextValue},
};

use anyhow::anyhow;

use crate::{define_rb_intern, error};
use magnus::{
class, function, gc::Marker, method, prelude::*, scan_args, typed_data::Obj, DataTypeFunctions,
Expand Down
6 changes: 3 additions & 3 deletions ext/src/ruby_api/trap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ impl From<Trap> for Error {
}
}

impl TryFrom<anyhow::Error> for Trap {
type Error = anyhow::Error;
impl TryFrom<wasmtime::Error> for Trap {
type Error = wasmtime::Error;

fn try_from(value: anyhow::Error) -> Result<Self, Self::Error> {
fn try_from(value: wasmtime::Error) -> Result<Self, Self::Error> {
match value.downcast_ref::<wasmtime::Trap>() {
Some(trap) => {
let trap = trap.to_owned();
Expand Down

0 comments on commit 70f5075

Please sign in to comment.