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
@@ -55,7 +55,7 @@ pub fn define_func(
|
||||
let method = names.user_error_conversion_method(&user_err);
|
||||
quote!(UserErrorConversion::#method(ctx, e))
|
||||
} else {
|
||||
quote!(e)
|
||||
quote!(Ok(e))
|
||||
};
|
||||
quote! {
|
||||
let e = #conversion;
|
||||
@@ -63,7 +63,10 @@ pub fn define_func(
|
||||
#rt::tracing::Level::TRACE,
|
||||
#name = #rt::tracing::field::debug(&e),
|
||||
);
|
||||
return #abi_ret::from(e);
|
||||
match e {
|
||||
Ok(e) => { return Ok(#abi_ret::from(e)); },
|
||||
Err(e) => { return Err(e); },
|
||||
}
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|| quote!(()));
|
||||
@@ -79,7 +82,7 @@ pub fn define_func(
|
||||
quote! {
|
||||
let e = #rt::GuestError::InFunc { funcname: #funcname, location: #location, err: Box::new(e.into()) };
|
||||
let err: #err_typename = GuestErrorConversion::#err_method(ctx, e);
|
||||
return #abi_ret::from(err);
|
||||
return Ok(#abi_ret::from(err));
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
@@ -161,17 +164,17 @@ pub fn define_func(
|
||||
#rt::tracing::Level::TRACE,
|
||||
success=#rt::tracing::field::display(&success)
|
||||
);
|
||||
#abi_ret::from(success)
|
||||
Ok(#abi_ret::from(success))
|
||||
}
|
||||
} else {
|
||||
quote!()
|
||||
quote!(Ok(()))
|
||||
};
|
||||
|
||||
let trait_name = names.trait_name(&module.name);
|
||||
let mod_name = &module.name.as_str();
|
||||
let func_name = &func.name.as_str();
|
||||
|
||||
quote!(pub fn #ident(#abi_args) -> #abi_ret {
|
||||
quote!(pub fn #ident(#abi_args) -> Result<#abi_ret, String> {
|
||||
let _span = #rt::tracing::span!(
|
||||
#rt::tracing::Level::TRACE,
|
||||
"wiggle abi",
|
||||
|
||||
Reference in New Issue
Block a user