Macro hdi::prelude::result::wasm_error
macro_rules! wasm_error {
($e:expr) => { ... };
($($arg:tt)*) => { ... };
}
Expand description
Helper macro for returning an error from a WASM.
Automatically included in the error are the file and the line number where the
error occurred. The error type is one of the WasmErrorInner
variants.
This macro is the recommended way of returning an error from a Zome function.
If a single expression is passed to wasm_error!
the result will be converted
to a WasmErrorInner
via into()
so string and WasmErrorInner
values are
both supported directly.
If a list of arguments is passed to wasm_error!
it will first be forwarded
to format!
and then the resultant string converted to WasmErrorInner
.
As the string->WasmErrorInner conversion is handled by a call to into, the
feature error_as_host
can be used so that WasmErrorInner::Host
is produced
by the macro from any passed/generated string.
Examples
Err(wasm_error!(WasmErrorInner::Guest("entry not found".to_string())));
Err(wasm_error!("entry not found"));
Err(wasm_error!("{} {}", "entry", "not found"));
Err(wasm_error!(WasmErrorInner::Host("some host error".into())));