pub enum VMError {
Show 16 variants
StackUnderflow,
StackOverflow,
TypeError {
expected: &'static str,
got: &'static str,
},
DivisionByZero,
UndefinedVariable(String),
UndefinedProperty(String),
InvalidCall,
IndexOutOfBounds {
index: i32,
length: usize,
},
InvalidOperand,
ArityMismatch {
function: String,
expected: usize,
got: usize,
},
InvalidArgument {
function: String,
message: String,
},
NotImplemented(String),
RuntimeError(String),
Suspended {
future_id: u64,
resume_ip: usize,
},
Interrupted,
ResumeRequested,
}Expand description
VM runtime errors
Variants§
StackUnderflow
Stack underflow
StackOverflow
Stack overflow
TypeError
Type mismatch
DivisionByZero
Division by zero
UndefinedVariable(String)
Variable not found
UndefinedProperty(String)
Property not found
InvalidCall
Invalid function call
IndexOutOfBounds
Invalid array index
InvalidOperand
Invalid operand
ArityMismatch
Wrong number of arguments passed to a function
InvalidArgument
Invalid argument value (correct type, wrong value)
NotImplemented(String)
Feature not yet implemented
RuntimeError(String)
Runtime error with message
Suspended
VM suspended on await — not a real error, used to propagate suspension up the Rust call stack
Interrupted
Execution interrupted by Ctrl+C signal
ResumeRequested
Internal: state.resume() requested VM state restoration. Not a real error — intercepted by the dispatch loop.
Implementations§
Source§impl VMError
impl VMError
Sourcepub fn type_mismatch(expected: &'static str, got: &'static str) -> Self
pub fn type_mismatch(expected: &'static str, got: &'static str) -> Self
Convenience constructor for TypeError { expected, got }.
Sourcepub fn argument_count_error(
fn_name: impl Into<String>,
expected: usize,
got: usize,
) -> Self
pub fn argument_count_error( fn_name: impl Into<String>, expected: usize, got: usize, ) -> Self
Convenience constructor for argument-count errors.
Produces ArityMismatch { function, expected, got } with a consistent
message format: "fn_name() expects N argument(s), got M".
Prefer this over hand-writing VMError::RuntimeError(format!(...)) for
arity mismatches — it uses the structured ArityMismatch variant which
tools can match on programmatically.
Sourcepub fn type_error(fn_name: &str, expected_type: &str, got_value: &str) -> Self
pub fn type_error(fn_name: &str, expected_type: &str, got_value: &str) -> Self
Convenience constructor for type errors in builtin/stdlib functions.
Produces a RuntimeError with the format:
"fn_name(): expected <expected_type>, got <got_value>".
Use this when a function receives a value of the wrong type. For the
lower-level TypeError { expected, got } variant (which requires
&'static str), use VMError::type_mismatch() instead.
Trait Implementations§
Source§impl Error for VMError
impl Error for VMError
1.30.0 · 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()