pub enum WasmError {
LoadFailed {
path: PathBuf,
source: Error,
suggestion: Option<String>,
},
FunctionNotFound {
function: String,
module: String,
suggestion: Option<String>,
},
GuestError {
code: i32,
message: Option<String>,
},
SerializationFailed(String),
MemoryAccessFailed {
reason: String,
},
}Expand description
Errors related to loading and executing WASM plugins
Only available when the wasm-plugins feature is enabled.
These errors occur when loading a .wasm module, validating its
mandatory exports, or invoking a guest function across the host/guest
boundary. See WASM_PLUGIN_INTERFACE.md for the full ABI contract.
Variants§
LoadFailed
The .wasm module could not be loaded or instantiated
§Example
use dynamic_cli::error::WasmError;
use std::path::PathBuf;
let error = WasmError::LoadFailed {
path: PathBuf::from("plugin.wasm"),
source: anyhow::anyhow!("invalid magic number"),
suggestion: Some("Verify the file is a valid WASM binary.".to_string()),
};
let msg = format!("{}", error);
assert!(msg.contains("plugin.wasm"));Fields
FunctionNotFound
A mandatory or mapped export is missing from the module
Mandatory exports are memory, dcli_alloc, dcli_dealloc, and the
mapped business function. See WASM_PLUGIN_INTERFACE.md.
§Example
use dynamic_cli::error::WasmError;
let error = WasmError::FunctionNotFound {
function: "dcli_dealloc".to_string(),
module: "plugin.wasm".to_string(),
suggestion: Some(
"Export `dcli_dealloc(ptr: i32, size: i32)` from the WASM module.".to_string()
),
};
let msg = format!("{}", error);
assert!(msg.contains("dcli_dealloc"));Fields
GuestError
The guest function returned a non-zero error code
message is populated from dcli_last_error_message() when the
module exports it; otherwise None.
§Example
use dynamic_cli::error::WasmError;
let error = WasmError::GuestError {
code: 1,
message: Some("invalid argument".to_string()),
};
let msg = format!("{}", error);
assert!(msg.contains('1'));Fields
SerializationFailed(String)
Failed to serialize handler arguments before crossing the WASM boundary
§Example
use dynamic_cli::error::WasmError;
let error = WasmError::SerializationFailed("unsupported map key type".to_string());
let msg = format!("{}", error);
assert!(msg.contains("unsupported map key type"));MemoryAccessFailed
Failed to read from or write to the guest’s linear memory
§Example
use dynamic_cli::error::WasmError;
let error = WasmError::MemoryAccessFailed {
reason: "write out of bounds".to_string(),
};
let msg = format!("{}", error);
assert!(msg.contains("out of bounds"));Implementations§
Source§impl WasmError
impl WasmError
Sourcepub fn missing_mandatory_export(function: &str, module: &str) -> Self
pub fn missing_mandatory_export(function: &str, module: &str) -> Self
Create a FunctionNotFound error for a missing mandatory export
The suggestion names the exact signature expected for the missing
export, taken from WASM_PLUGIN_INTERFACE.md.
§Example
use dynamic_cli::error::WasmError;
let error = WasmError::missing_mandatory_export("dcli_alloc", "plugin.wasm");
match error {
WasmError::FunctionNotFound { suggestion, .. } => {
assert!(suggestion.is_some());
}
_ => panic!("wrong variant"),
}Sourcepub fn guest_error_without_message(code: i32) -> Self
pub fn guest_error_without_message(code: i32) -> Self
Create a GuestError from a raw error code, without a detailed message
Used when the module does not export dcli_last_error_message.
§Example
use dynamic_cli::error::WasmError;
let error = WasmError::guest_error_without_message(2);
match error {
WasmError::GuestError { code, message } => {
assert_eq!(code, 2);
assert!(message.is_none());
}
_ => panic!("wrong variant"),
}Trait Implementations§
Source§impl Error for WasmError
impl Error for WasmError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for WasmError
impl RefUnwindSafe for WasmError
impl Send for WasmError
impl Sync for WasmError
impl Unpin for WasmError
impl UnsafeUnpin for WasmError
impl UnwindSafe for WasmError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more