Skip to content

Commit db7ec95

Browse files
author
Pat Hickey
authored
Merge pull request #2760 from bytecodealliance/pch/wiggle_error_reporting
wiggle: delete GuestErrorConversion, improve some error reporting
2 parents d4b54ee + df18b44 commit db7ec95

23 files changed

Lines changed: 21 additions & 123 deletions

File tree

crates/wasi-common/src/snapshots/preview_0.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ impl wiggle::GuestErrorType for types::Errno {
2424
}
2525
}
2626

27-
impl types::GuestErrorConversion for WasiCtx {
28-
fn into_errno(&self, e: wiggle::GuestError) -> types::Errno {
29-
debug!("Guest error: {:?}", e);
30-
let snapshot1_errno: snapshot1_types::Errno = e.into();
31-
snapshot1_errno.into()
32-
}
33-
}
34-
3527
impl types::UserErrorConversion for WasiCtx {
3628
fn errno_from_error(&self, e: Error) -> Result<types::Errno, wiggle::Trap> {
3729
debug!("Error: {:?}", e);

crates/wasi-common/src/snapshots/preview_1.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ impl wiggle::GuestErrorType for types::Errno {
3030
}
3131
}
3232

33-
impl types::GuestErrorConversion for WasiCtx {
34-
fn into_errno(&self, e: wiggle::GuestError) -> types::Errno {
35-
debug!("Guest error: {:?}", e);
36-
e.into()
37-
}
38-
}
39-
4033
impl types::UserErrorConversion for WasiCtx {
4134
fn errno_from_error(&self, e: Error) -> Result<types::Errno, wiggle::Trap> {
4235
debug!("Error: {:?}", e);
@@ -103,7 +96,6 @@ impl From<wiggle::GuestError> for types::Errno {
10396
InvalidUtf8 { .. } => Self::Ilseq,
10497
TryFromIntError { .. } => Self::Overflow,
10598
InFunc { err, .. } => types::Errno::from(*err),
106-
InDataField { err, .. } => types::Errno::from(*err),
10799
SliceLengthsDiffer { .. } => Self::Fault,
108100
BorrowCheckerOutOfHandles { .. } => Self::Fault,
109101
}

crates/wasi-crypto/src/wiggle_interfaces/error.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,6 @@ impl<'a> wiggle::GuestErrorType for guest_types::CryptoErrno {
5252
}
5353
}
5454

55-
impl guest_types::GuestErrorConversion for WasiCryptoCtx {
56-
fn into_crypto_errno(&self, e: wiggle::GuestError) -> guest_types::CryptoErrno {
57-
eprintln!("GuestError (witx) {:?}", e);
58-
guest_types::CryptoErrno::GuestError
59-
}
60-
}
61-
6255
impl From<wiggle::GuestError> for guest_types::CryptoErrno {
6356
fn from(e: wiggle::GuestError) -> Self {
6457
eprintln!("GuestError (impl) {:?}", e);

crates/wasi-nn/src/witx.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ wiggle::from_witx!({
1010

1111
use types::NnErrno;
1212

13-
/// Wiggle generates code that performs some input validation on the arguments passed in by users of
14-
/// wasi-nn. Here we convert the validation error into one (or more, eventually) of the error
15-
/// variants defined in the witx.
16-
impl types::GuestErrorConversion for WasiNnCtx {
17-
fn into_nn_errno(&self, e: wiggle::GuestError) -> NnErrno {
18-
eprintln!("Guest error: {:?}", e);
19-
NnErrno::InvalidArgument
20-
}
21-
}
22-
2313
impl<'a> types::UserErrorConversion for WasiNnCtx {
2414
fn nn_errno_from_wasi_nn_error(&self, e: WasiNnError) -> Result<NnErrno, wiggle::Trap> {
2515
eprintln!("Host error: {:?}", e);

crates/wiggle/generate/src/funcs.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,12 @@ impl witx::Bindgen for Rust<'_> {
139139
) {
140140
let rt = self.rt;
141141
let wrap_err = |location: &str| {
142+
let modulename = self.module.name.as_str();
142143
let funcname = self.funcname;
143144
quote! {
144145
|e| {
145146
#rt::GuestError::InFunc {
147+
modulename: #modulename,
146148
funcname: #funcname,
147149
location: #location,
148150
err: Box::new(#rt::GuestError::from(e)),

crates/wiggle/generate/src/lib.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,6 @@ pub fn generate(doc: &witx::Document, names: &Names, settings: &CodegenSettings)
3838
}
3939
});
4040

41-
let guest_error_methods = doc.error_types().map(|t| {
42-
let typename = names.type_ref(&t, anon_lifetime());
43-
let err_method = names.guest_error_conversion_method(&t);
44-
quote!(fn #err_method(&self, e: #rt::GuestError) -> #typename;)
45-
});
46-
let guest_error_conversion = quote! {
47-
pub trait GuestErrorConversion {
48-
#(#guest_error_methods)*
49-
}
50-
};
51-
5241
let user_error_methods = settings.errors.iter().map(|errtype| {
5342
let abi_typename = names.type_ref(&errtype.abi_type(), anon_lifetime());
5443
let user_typename = errtype.typename();
@@ -82,7 +71,6 @@ pub fn generate(doc: &witx::Document, names: &Names, settings: &CodegenSettings)
8271

8372
#(#types)*
8473
#(#constants)*
85-
#guest_error_conversion
8674
#user_error_conversion
8775
}
8876
#(#modules)*

crates/wiggle/generate/src/names.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,6 @@ impl Names {
196196
}
197197
}
198198

199-
pub fn guest_error_conversion_method(&self, tref: &TypeRef) -> Ident {
200-
let suffix = Self::snake_typename(tref);
201-
format_ident!("into_{}", suffix)
202-
}
203-
204199
pub fn user_error_conversion_method(&self, user_type: &UserErrorType) -> Ident {
205200
let abi_type = Self::snake_typename(&user_type.abi_type());
206201
format_ident!(

crates/wiggle/macro/src/lib.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,6 @@ use syn::parse_macro_input;
113113
/// }
114114
/// }
115115
///
116-
/// /// The `types::GuestErrorConversion` trait is also generated with a method for
117-
/// /// each type used in the `error` position. This trait allows wiggle-generated
118-
/// /// code to convert a `wiggle::GuestError` into the right error type. The trait
119-
/// /// must be implemented for the user's ctx type.
120-
///
121-
/// impl types::GuestErrorConversion for YourCtxType {
122-
/// fn into_errno(&self, _e: wiggle::GuestError) -> types::Errno {
123-
/// unimplemented!()
124-
/// }
125-
/// }
126-
///
127116
/// /// If you specify a `error` mapping to the macro, you must implement the
128117
/// /// `types::UserErrorConversion` for your ctx type as well. This trait gives
129118
/// /// you an opportunity to store or log your rich error type, while returning

crates/wiggle/src/error.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,14 @@ pub enum GuestError {
1919
BorrowCheckerOutOfHandles,
2020
#[error("Slice length mismatch")]
2121
SliceLengthsDiffer,
22-
#[error("In func {funcname}:{location}:")]
22+
#[error("In func {modulename}::{funcname} at {location}: {err}")]
2323
InFunc {
24+
modulename: &'static str,
2425
funcname: &'static str,
2526
location: &'static str,
2627
#[source]
2728
err: Box<GuestError>,
2829
},
29-
#[error("In data {typename}.{field}:")]
30-
InDataField {
31-
typename: String,
32-
field: String,
33-
#[source]
34-
err: Box<GuestError>,
35-
},
3630
#[error("Invalid UTF-8 encountered: {0:?}")]
3731
InvalidUtf8(#[from] ::std::str::Utf8Error),
3832
#[error("Int conversion error: {0:?}")]

crates/wiggle/test-helpers/examples/tracing.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ witx_literal: "
2727
errors: { errno => RichError },
2828
});
2929

30-
// The impl of GuestErrorConversion works just like in every other test where
31-
// we have a single error type with witx `$errno` with the success called `$ok`
32-
impl_errno!(types::Errno, types::GuestErrorConversion);
30+
impl_errno!(types::Errno);
3331

3432
/// When the `errors` mapping in witx is non-empty, we need to impl the
3533
/// types::UserErrorConversion trait that wiggle generates from that mapping.

0 commit comments

Comments
 (0)