#[non_exhaustive]pub enum RuntimeError {
Show 26 variants
Nil {
access_origin: Origin,
},
NonSingleton {
access_origin: Origin,
actual: usize,
},
ShortSlice {
access_origin: Origin,
minimum: usize,
actual: usize,
},
OutOfBounds {
access_origin: Origin,
index: usize,
length: usize,
},
ReadOnly {
access_origin: Origin,
data_origin: Origin,
},
WriteOnly {
access_origin: Origin,
data_origin: Origin,
},
ReadToWrite {
access_origin: Origin,
borrow_origin: Origin,
},
WriteToRead {
access_origin: Origin,
borrow_origin: Origin,
},
WriteToWrite {
access_origin: Origin,
borrow_origin: Origin,
},
Utf8Decoding {
access_origin: Origin,
cause: Box<Utf8Error>,
},
BorrowLimit {
access_origin: Origin,
limit: usize,
},
TypeMismatch {
access_origin: Origin,
data_type: &'static TypeMeta,
expected_types: Vec<&'static TypeMeta>,
},
DowncastStatic {
access_origin: Origin,
},
UpcastResult {
access_origin: Origin,
cause: Arc<dyn StdError + Send + Sync + 'static>,
},
NumberCast {
access_origin: Origin,
from: &'static TypeMeta,
to: &'static TypeMeta,
cause: NumberCastCause,
value: Arc<dyn NumValue>,
},
NumericOperation {
invoke_origin: Origin,
kind: NumericOperationKind,
lhs: (&'static TypeMeta, Arc<dyn NumValue>),
rhs: Option<(&'static TypeMeta, Arc<dyn NumValue>)>,
target: &'static TypeMeta,
},
RangeCast {
access_origin: Origin,
from: Range<usize>,
to: &'static str,
},
MalformedRange {
access_origin: Origin,
start_bound: usize,
end_bound: usize,
},
PrimitiveParse {
access_origin: Origin,
from: String,
to: &'static TypeMeta,
cause: Arc<dyn StdError + Send + Sync + 'static>,
},
ArityMismatch {
invocation_origin: Origin,
function_origin: Origin,
parameters: usize,
arguments: usize,
},
UndefinedOperator {
access_origin: Origin,
receiver_origin: Option<Origin>,
receiver_type: &'static TypeMeta,
operator: OperatorKind,
},
UnknownField {
access_origin: Origin,
receiver_origin: Origin,
receiver_type: &'static TypeMeta,
field: String,
},
FormatError {
access_origin: Origin,
receiver_origin: Origin,
},
UnknownPackage {
access_origin: Origin,
name: &'static str,
version: &'static str,
},
Interrupted {
origin: Origin,
},
StackOverflow {
origin: Origin,
},
}
Expand description
Represents any error that may occur during the evaluation of Script code.
This object implements the Debug and Display traits. The Display implementation provides a brief description of the underlying error.
However, it is recommended to use the RuntimeError::display function instead, as it renders the script’s source code and annotates it with detailed error messages.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Nil
The script code attempts to access Nil data.
NonSingleton
The script code attempts to access an object representing an array with zero or more than one element.
Fields
ShortSlice
The script array is too short and cannot be interpreted as an array with the requested number of elements.
Fields
OutOfBounds
The script code attempts to index into an array or string, but the index is out of bounds.
Fields
ReadOnly
The script code attempts to mutate an object that only provides read-only access.
Fields
WriteOnly
The script code attempts to read an object that only provides mutation access.
Fields
ReadToWrite
The script code attempts to mutate an object that is currently borrowed for reading.
Fields
WriteToRead
The script code attempts to read an object that is currently borrowed for writing.
Fields
WriteToWrite
The script code attempts to borrow data for mutation more than once at a time.
Fields
Utf8Decoding
The script attempts to decode a byte array that is not a valid UTF-8 encoding.
Fields
BorrowLimit
The script attempts to borrow data too many times simultaneously.
Fields
TypeMismatch
The script attempts to use a data object as an argument for a function or an operator, but the data type does not meet the requirements.
Fields
DowncastStatic
The script attempts to dereference a data object, but the data object does not live long enough.
UpcastResult
The script calls a Rust function that results in Result::Err.
Fields
NumberCast
The script attempts to cast one numeric type into another, but the conversion is not possible for the specified source number value and the requested destination type.
Fields
access_origin: Origin
The range in Rust or Script source code where the numeric object was accessed for conversion.
cause: NumberCastCause
The cause of the failure.
NumericOperation
The script attempts to perform an operation between two primitive numeric values (or on a single numeric value), but the operation results in an error due to specific reasons (e.g., numeric overflow).
Fields
kind: NumericOperationKind
The type of numeric operation.
RangeCast
The script attempts to cast a Range object into another range type
(e.g., 100..200
into 100..=199
), but such casting is not possible
due to unsatisfied bounds.
Fields
MalformedRange
The script attempts to use a malformed range (e.g., 200..100
).
Fields
PrimitiveParse
The script attempts to parse a string into a primitive type, but the string is malformed and cannot be interpreted as the requested primitive type.
Fields
ArityMismatch
The script attempts to call a function with an incorrect number of arguments, either too few or too many.
Fields
UndefinedOperator
The script attempts to apply an operator to an object, but the object’s type does not support this operator.
Fields
receiver_origin: Option<Origin>
The range in Rust or Script source code where the object was created. If omitted, the object instance has not been created yet (e.g., the operator is an instantiation operator).
operator: OperatorKind
The type of operator.
UnknownField
The script attempts to access a field of an object, but the object does not have the specified field.
Fields
FormatError
The script attempts to format a data object using the Debug or Display implementations, but the formatter returns an error.
Fields
UnknownPackage
The script attempts to access a package that is not fully registered (e.g., the export system has been switched to a shallow mode).
Fields
Interrupted
The script evaluation has been interrupted by the thread’s runtime hook.
StackOverflow
The script has been interrupted because the interpreter’s memory stack for the thread overflowed.
Implementations§
Source§impl RuntimeError
impl RuntimeError
Sourcepub fn display<'a>(
&self,
resolver: &'a impl ModuleTextResolver,
) -> impl Display + 'a
pub fn display<'a>( &self, resolver: &'a impl ModuleTextResolver, ) -> impl Display + 'a
Returns a printable object that renders the script’s source code and annotates it with error messages describing the underlying error object and pointing to the source code location(s) where the error occurred.
This function provides a canonical way to print end-user-facing script evaluation error messages.
The resolver
parameter specifies an object through which the returned
printer accesses the ModuleText.
In a multi-module environment, a RuntimeError may occur in any of these modules and could potentially relate to several scripts. The resolver allows the printer to access their source code texts when formatting the message.
If your runtime configuration consists of just one script module, or if
you are confident that the modules are semantically isolated from each
other (by default, modules are isolated), you can directly use the
ModuleText of the script module as the
resolver
argument.
Sourcepub fn primary_origin(&self) -> &Origin
pub fn primary_origin(&self) -> &Origin
Returns the Rust or Script source code range where the error occurred.
Sourcepub fn secondary_origin(&self) -> Option<&Origin>
pub fn secondary_origin(&self) -> Option<&Origin>
Returns an additional Rust or Script source code range that hints at an extra location related to the cause of the error.
For example, the ReadToWrite error variant includes an additional location that indicates the previous borrowing site.
Most error variants do not have an extra location, and in such cases, this function will return None.
Sourcepub fn primary_description(&self) -> String
pub fn primary_description(&self) -> String
Returns an error message string related to the primary_origin.
This function returns the same message string that you would get by formatting RuntimeError using the Display implementation.
Sourcepub fn secondary_description(&self) -> String
pub fn secondary_description(&self) -> String
Returns an error message string related to the secondary_origin.
If the error variant does not have an extra location, this function returns an empty string.
Sourcepub fn summary(&self) -> String
pub fn summary(&self) -> String
Returns a detailed summary of this error.
This message is the same one that would be printed in the footer of the RuntimeError::display object.
Trait Implementations§
Source§impl Clone for RuntimeError
impl Clone for RuntimeError
Source§fn clone(&self) -> RuntimeError
fn clone(&self) -> RuntimeError
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for RuntimeError
impl Debug for RuntimeError
Source§impl Display for RuntimeError
impl Display for RuntimeError
Source§impl Error for RuntimeError
impl Error for RuntimeError
Source§fn source(&self) -> Option<&(dyn StdError + 'static)>
fn source(&self) -> Option<&(dyn StdError + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Auto Trait Implementations§
impl Freeze for RuntimeError
impl !RefUnwindSafe for RuntimeError
impl Send for RuntimeError
impl Sync for RuntimeError
impl Unpin for RuntimeError
impl !UnwindSafe for RuntimeError
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString
. Read more