Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/wiggle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ wiggle-macro = { workspace = true }
tracing = { workspace = true }
bitflags = { workspace = true }
wasmtime = { workspace = true, optional = true }
anyhow = { workspace = true }
wasmtime-environ = { workspace = true }

[dev-dependencies]
wiggle-test = { path = "test-helpers" }
Expand Down
2 changes: 1 addition & 1 deletion crates/wiggle/generate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ witx = "0.9.1"
quote = { workspace = true }
proc-macro2 = { workspace = true }
heck = { workspace = true }
anyhow = { workspace = true }
wasmtime-environ = { workspace = true }
syn = { workspace = true, features = ["full"] }
10 changes: 5 additions & 5 deletions crates/wiggle/generate/src/codegen_settings.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::config::{AsyncConf, ErrorConf, ErrorConfField, TracingConf};
use anyhow::{Error, anyhow};
use proc_macro2::{Ident, TokenStream};
use quote::quote;
use std::collections::HashMap;
use std::rc::Rc;
use wasmtime_environ::error::{Error, format_err};
use witx::{Document, Id, InterfaceFunc, Module, NamedType, TypeRef};

pub use crate::config::Asyncness;
Expand Down Expand Up @@ -58,13 +58,13 @@ impl ErrorTransform {
ErrorConfField::Trappable(field) => if let Some(abi_type) = doc.typename(&Id::new(ident.to_string())) {
Ok(ErrorType::Generated(TrappableErrorType { abi_type, rich_type: field.rich_error.clone() }))
} else {
Err(anyhow!("No witx typename \"{}\" found", ident.to_string()))
Err(format_err!("No witx typename \"{}\" found", ident.to_string()))
},
ErrorConfField::User(field) => if let Some(abi_type) = doc.typename(&Id::new(ident.to_string())) {
if let Some(ident) = field.rich_error.get_ident() {
if let Some(prior_def) = richtype_identifiers.insert(ident.clone(), field.err_loc)
{
return Err(anyhow!(
return Err(format_err!(
"duplicate rich type identifier of {ident:?} not allowed. prior definition at {prior_def:?}",
));
}
Expand All @@ -74,13 +74,13 @@ impl ErrorTransform {
method_fragment: ident.to_string()
}))
} else {
return Err(anyhow!(
return Err(format_err!(
"rich error type must be identifier for now - TODO add ability to provide a corresponding identifier: {:?}",
field.err_loc
))
}
}
else { Err(anyhow!("No witx typename \"{}\" found", ident.to_string())) }
else { Err(format_err!("No witx typename \"{}\" found", ident.to_string())) }
}
).collect::<Result<Vec<_>, Error>>()?;
Ok(Self { m })
Expand Down
4 changes: 2 additions & 2 deletions crates/wiggle/generate/src/funcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn _define_func(
ctx: #ctx_type (impl #(#bounds)+*),
memory: &mut wiggle::GuestMemory<'_>,
#(#abi_params),*
) -> wiggle::anyhow::Result<#abi_ret> {
) -> wiggle::error::Result<#abi_ret> {
use std::convert::TryFrom as _;
#traced_body
}
Expand Down Expand Up @@ -128,7 +128,7 @@ fn _define_func(
ctx: #ctx_type (impl #(#bounds)+*),
memory: &mut wiggle::GuestMemory<'_>,
#(#abi_params),*
) -> wiggle::anyhow::Result<#abi_ret> {
) -> wiggle::error::Result<#abi_ret> {
use std::convert::TryFrom as _;
#traced_body
}
Expand Down
2 changes: 1 addition & 1 deletion crates/wiggle/generate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn generate(doc: &witx::Document, settings: &CodegenSettings) -> TokenStream
let methodname = names::user_error_conversion_method(&errtype);
Some(quote! {
fn #methodname(&mut self, e: super::#user_typename)
-> wiggle::anyhow::Result<#abi_typename>;
-> wiggle::error::Result<#abi_typename>;
})
}
ErrorType::Generated(_) => None,
Expand Down
2 changes: 1 addition & 1 deletion crates/wiggle/generate/src/module_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn define_module_trait(m: &Module, settings: &CodegenSettings) -> TokenStrea
});

let mut result = match f.results.len() {
0 if f.noreturn => quote!(wiggle::anyhow::Error),
0 if f.noreturn => quote!(wiggle::error::Error),
0 => quote!(()),
1 => {
let (ok, err) = match &**f.results[0].tref.type_() {
Expand Down
8 changes: 4 additions & 4 deletions crates/wiggle/generate/src/types/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub(super) fn define_error(
quote! {
#[derive(Debug)]
pub struct #rich_error {
inner: anyhow::Error,
inner: wiggle::error::Error,
}

impl std::fmt::Display for #rich_error {
Expand All @@ -30,10 +30,10 @@ pub(super) fn define_error(
}

impl #rich_error {
pub fn trap(inner: anyhow::Error) -> #rich_error {
pub fn trap(inner: wiggle::error::Error) -> #rich_error {
Self { inner }
}
pub fn downcast(self) -> Result<#abi_error, anyhow::Error> {
pub fn downcast(self) -> Result<#abi_error, wiggle::error::Error> {
self.inner.downcast()
}
pub fn downcast_ref(&self) -> Option<&#abi_error> {
Expand All @@ -46,7 +46,7 @@ pub(super) fn define_error(

impl From<#abi_error> for #rich_error {
fn from(abi: #abi_error) -> #rich_error {
#rich_error { inner: anyhow::Error::from(abi) }
#rich_error { inner: wiggle::error::Error::from(abi) }
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/wiggle/generate/src/wasmtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn link_module(
pub fn #func_name<T, U>(
linker: &mut wiggle::wasmtime_crate::Linker<T>,
get_cx: impl Fn(&mut T) -> #u + Send + Sync + Copy + 'static,
) -> wiggle::anyhow::Result<()>
) -> wiggle::error::Result<()>
where
T: 'static,
U: #ctx_bound #send_bound
Expand Down Expand Up @@ -126,7 +126,7 @@ fn generate_func(
let ctx = get_cx(caller.data_mut());
(wiggle::GuestMemory::Shared(m.data()), ctx)
}
_ => wiggle::anyhow::bail!("missing required memory export"),
_ => wiggle::error::bail!("missing required memory export"),
};
Ok(<#ret_ty>::from(#abi_func(ctx, &mut mem #(, #arg_names)*) #await_ ?))
};
Expand All @@ -150,7 +150,7 @@ fn generate_func(
linker.func_wrap(
#module_str,
#field_str,
move |mut caller: wiggle::wasmtime_crate::Caller<'_, T> #(, #arg_decls)*| -> wiggle::anyhow::Result<#ret_ty> {
move |mut caller: wiggle::wasmtime_crate::Caller<'_, T> #(, #arg_decls)*| -> wiggle::error::Result<#ret_ty> {
let result = async { #body };
#block_with(result)?
},
Expand All @@ -163,7 +163,7 @@ fn generate_func(
linker.func_wrap(
#module_str,
#field_str,
move |mut caller: wiggle::wasmtime_crate::Caller<'_, T> #(, #arg_decls)*| -> wiggle::anyhow::Result<#ret_ty> {
move |mut caller: wiggle::wasmtime_crate::Caller<'_, T> #(, #arg_decls)*| -> wiggle::error::Result<#ret_ty> {
#body
},
)?;
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions crates/wiggle/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
use anyhow::{Result, bail};
use std::borrow::Cow;
use std::cell::UnsafeCell;
use std::fmt;
use std::mem;
use std::ops::Range;
use std::str;
use wasmtime_environ::error::{Result, bail};

pub use wiggle_macro::from_witx;

pub use anyhow;
pub use wasmtime_environ::error;
pub use wiggle_macro::wasmtime_integration;

pub use bitflags;

#[cfg(feature = "wiggle_metadata")]
pub use witx;

mod error;
mod guest_error;
mod guest_type;
mod region;

pub use tracing;

pub use error::GuestError;
pub use guest_error::GuestError;
pub use guest_type::{GuestErrorType, GuestType, GuestTypeTransparent};
pub use region::Region;

Expand Down
2 changes: 1 addition & 1 deletion crates/wiggle/test-helpers/examples/tracing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use wiggle::GuestMemory;
use wiggle::error::Result;
use wiggle_test::{HostMemory, WasiCtx, impl_errno};

/// The `errors` argument to the wiggle gives us a hook to map a rich error
Expand Down
6 changes: 3 additions & 3 deletions crates/wiggle/tests/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// Execute the wiggle guest conversion code to exercise it
mod convert_just_errno {
use anyhow::Result;
use wiggle::GuestMemory;
use wiggle::error::Result;
use wiggle_test::{HostMemory, WasiCtx, impl_errno};

/// The `errors` argument to the wiggle gives us a hook to map a rich error
Expand Down Expand Up @@ -93,8 +93,8 @@ mod convert_just_errno {
/// we use two distinct error types.
mod convert_multiple_error_types {
pub use super::convert_just_errno::RichError;
use anyhow::Result;
use wiggle::GuestMemory;
use wiggle::error::Result;
use wiggle_test::{WasiCtx, impl_errno};

/// Test that we can map multiple types of errors.
Expand Down Expand Up @@ -152,7 +152,7 @@ mod convert_multiple_error_types {
fn bar(&mut self, _: &mut GuestMemory<'_>, _: u32) -> Result<(), AnotherRichError> {
unimplemented!()
}
fn baz(&mut self, _: &mut GuestMemory<'_>, _: u32) -> anyhow::Error {
fn baz(&mut self, _: &mut GuestMemory<'_>, _: u32) -> wiggle::error::Error {
unimplemented!()
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/wiggle/tests/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ impl<'a> crate::wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx<'a> {
&mut self,
_memory: &mut GuestMemory<'_>,
_rval: types::Exitcode,
) -> anyhow::Error {
) -> wiggle::error::Error {
unimplemented!("proc_exit")
}

Expand Down