From 39ded32195f70e13d302566bc75b60ea08523371 Mon Sep 17 00:00:00 2001 From: Jimmy Bourassa Date: Sun, 3 Nov 2024 12:38:33 -0600 Subject: [PATCH] Remove anyhow dependency Instead, rely on wasmtime's re-exported `anyhow::Result` and `anyhow::Error`. One less package to update, and no need to keep version in sync. --- Cargo.lock | 1 - ext/Cargo.toml | 1 - ext/src/ruby_api/func.rs | 6 +++--- ext/src/ruby_api/store.rs | 10 +++++----- ext/src/ruby_api/table.rs | 2 -- ext/src/ruby_api/trap.rs | 6 +++--- 6 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bba7b117..527b83ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2035,7 +2035,6 @@ dependencies = [ name = "wasmtime-rb" version = "9.0.4" dependencies = [ - "anyhow", "async-timer", "cap-std", "deterministic-wasi-ctx", diff --git a/ext/Cargo.toml b/ext/Cargo.toml index 8738ec38..5cc197b2 100644 --- a/ext/Cargo.toml +++ b/ext/Cargo.toml @@ -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", diff --git a/ext/src/ruby_api/func.rs b/ext/src/ruby_api/func.rs index eb7637c3..014f5c28 100644 --- a/ext/src/ruby_api/func.rs +++ b/ext/src/ruby_api/func.rs @@ -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("")) }}; } @@ -257,7 +257,7 @@ macro_rules! result_error { pub fn make_func_closure( ty: &wasmtime::FuncType, callable: Opaque, -) -> 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(); @@ -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(); } diff --git a/ext/src/ruby_api/store.rs b/ext/src/ruby_api/store.rs index 4474a355..496f1c1e 100644 --- a/ext/src/ruby_api/store.rs +++ b/ext/src/ruby_api/store.rs @@ -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::() { @@ -431,7 +431,7 @@ impl ResourceLimiter for TrackingResourceLimiter { current: usize, desired: usize, maximum: Option, - ) -> anyhow::Result { + ) -> wasmtime::Result { let res = self.inner.memory_growing(current, desired, maximum); // Update max_linear_memory_consumed @@ -457,16 +457,16 @@ impl ResourceLimiter for TrackingResourceLimiter { current: usize, desired: usize, maximum: Option, - ) -> anyhow::Result { + ) -> wasmtime::Result { 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) } diff --git a/ext/src/ruby_api/table.rs b/ext/src/ruby_api/table.rs index dec32ca6..36459513 100644 --- a/ext/src/ruby_api/table.rs +++ b/ext/src/ruby_api/table.rs @@ -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, diff --git a/ext/src/ruby_api/trap.rs b/ext/src/ruby_api/trap.rs index 8b3e3c33..68c2d253 100644 --- a/ext/src/ruby_api/trap.rs +++ b/ext/src/ruby_api/trap.rs @@ -96,10 +96,10 @@ impl From for Error { } } -impl TryFrom for Trap { - type Error = anyhow::Error; +impl TryFrom for Trap { + type Error = wasmtime::Error; - fn try_from(value: anyhow::Error) -> Result { + fn try_from(value: wasmtime::Error) -> Result { match value.downcast_ref::() { Some(trap) => { let trap = trap.to_owned();