Fixes #2418: Enhance wiggle to generate its UserErrorConverstion trait with a function that returns Result<abi_err, String> (#2419)
* Enhance wiggle to generate its UserErrorConverstion trait with a function that returns a Result<abi_err, String>. This enhancement allows hostcall implementations using wiggle to return an actionable error to the instance (the abi_err) or to terminate the instance using the String as fatal error information. * Enhance wiggle to generate its UserErrorConverstion trait with a function that returns a Result<abi_err, String>. This enhancement allows hostcall implementations using wiggle to return an actionable error to the instance (the abi_err) or to terminate the instance using the String as fatal error information. * Enhance the wiggle/wasmtime integration to leverage new work in ab7e9c6. Hostcall implementations generated by wiggle now return an Result<abi_error, Trap>. As a result, hostcalls experiencing fatal errors may trap, thereby terminating the wasmtime instance. This enhancement has been performed for both wasi snapshot1 and wasi snapshot0. * Update wasi-nn crate to reflect enhancement in issue #2418. * Update wiggle test-helpers for wiggle enhancement made in issue #2418. * Address PR feedback; omit verbose return statement. * Address PR feedback; manually format within a proc macro. * Address PR feedback; manually format proc macro. * Restore return statements to wasi.rs. * Restore return statements in funcs.rs. * Address PR feedback; omit TODO and fix formatting. * Ok-wrap error type in assert statement.
This commit is contained in:
committed by
GitHub
parent
128c3bd749
commit
b06ed39c1e
@@ -36,7 +36,7 @@ impl_errno!(types::Errno, types::GuestErrorConversion);
|
||||
/// When the `errors` mapping in witx is non-empty, we need to impl the
|
||||
/// types::UserErrorConversion trait that wiggle generates from that mapping.
|
||||
impl<'a> types::UserErrorConversion for WasiCtx<'a> {
|
||||
fn errno_from_rich_error(&self, e: RichError) -> types::Errno {
|
||||
fn errno_from_rich_error(&self, e: RichError) -> Result<types::Errno, String> {
|
||||
wiggle::tracing::debug!(
|
||||
rich_error = wiggle::tracing::field::debug(&e),
|
||||
"error conversion"
|
||||
@@ -46,8 +46,8 @@ impl<'a> types::UserErrorConversion for WasiCtx<'a> {
|
||||
self.log.borrow_mut().push(e.to_string());
|
||||
// Then do the trivial mapping down to the flat enum.
|
||||
match e {
|
||||
RichError::InvalidArg { .. } => types::Errno::InvalidArg,
|
||||
RichError::PicketLine { .. } => types::Errno::PicketLine,
|
||||
RichError::InvalidArg { .. } => Ok(types::Errno::InvalidArg),
|
||||
RichError::PicketLine { .. } => Ok(types::Errno::PicketLine),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ fn main() {
|
||||
let r0 = one_error_conversion::foo(&ctx, &host_memory, 0, 0, 8);
|
||||
assert_eq!(
|
||||
r0,
|
||||
i32::from(types::Errno::Ok),
|
||||
Ok(i32::from(types::Errno::Ok)),
|
||||
"Expected return value for strike=0"
|
||||
);
|
||||
assert!(ctx.log.borrow().is_empty(), "No error log for strike=0");
|
||||
@@ -99,7 +99,7 @@ fn main() {
|
||||
let r1 = one_error_conversion::foo(&ctx, &host_memory, 1, 0, 8);
|
||||
assert_eq!(
|
||||
r1,
|
||||
i32::from(types::Errno::PicketLine),
|
||||
Ok(i32::from(types::Errno::PicketLine)),
|
||||
"Expected return value for strike=1"
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -112,7 +112,7 @@ fn main() {
|
||||
let r2 = one_error_conversion::foo(&ctx, &host_memory, 2, 0, 8);
|
||||
assert_eq!(
|
||||
r2,
|
||||
i32::from(types::Errno::InvalidArg),
|
||||
Ok(i32::from(types::Errno::InvalidArg)),
|
||||
"Expected return value for strike=2"
|
||||
);
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user