virtual_machine/error.rs
1//! Error types and result handling for the Virtual Machine module.
2//!
3//! This module defines comprehensive error types that can occur during WASM module
4//! loading, compilation, instantiation, and execution.
5
6use alloc::string::String;
7use wamr_rust_sdk::RuntimeError;
8
9/// Result type alias for Virtual Machine operations
10pub type Result<T> = core::result::Result<T, Error>;
11
12/// Comprehensive error types for Virtual Machine operations
13///
14/// This enum covers all possible error conditions that can occur during
15/// WASM module lifecycle operations, from loading to execution.
16#[derive(Debug)]
17#[repr(C)]
18pub enum Error {
19 /// Invalid pointer provided to a function
20 InvalidPointer,
21
22 /// String contains invalid UTF-8 sequences
23 InvalidUtf8String,
24
25 /// Failed to convert between slice types
26 SliceConversionFailed(shared::Error),
27
28 /// Requested functionality is not yet implemented
29 NotImplemented,
30
31 /// WASM runtime initialization failed
32 InitializationFailure,
33
34 /// WASM module compilation failed with detailed error message
35 CompilationError(String),
36
37 /// WASM module instantiation failed with detailed error message
38 InstantiationFailure(String),
39
40 /// WASM function execution failed with detailed error message
41 ExecutionError(String),
42
43 /// Requested function was not found in the module
44 FunctionNotFound,
45
46 /// Memory allocation failed
47 AllocationFailure,
48
49 /// Failed to retrieve task information
50 FailedToGetTaskInformations(task::Error),
51
52 /// Mutex or lock was poisoned
53 PoisonedLock,
54
55 /// Invalid WASM module format or structure
56 InvalidModule,
57
58 /// Internal runtime error
59 InternalError,
60
61 /// Invalid thread identifier provided
62 InvalidThreadIdentifier,
63
64 /// Time-related operation failed
65 Time(time::Error),
66}
67
68impl From<RuntimeError> for Error {
69 fn from(error: RuntimeError) -> Self {
70 match error {
71 RuntimeError::NotImplemented => Error::NotImplemented,
72 RuntimeError::InitializationFailure => Error::InitializationFailure,
73 RuntimeError::WasmFileFSError(_) => Error::InitializationFailure,
74 RuntimeError::CompilationError(e) => Error::CompilationError(e),
75 RuntimeError::InstantiationFailure(e) => Error::InstantiationFailure(e),
76 RuntimeError::ExecutionError(e) => Error::ExecutionError(e.message),
77 RuntimeError::FunctionNotFound => Error::FunctionNotFound,
78 }
79 }
80}
81impl From<task::Error> for Error {
82 fn from(error: task::Error) -> Self {
83 Error::FailedToGetTaskInformations(error)
84 }
85}