#[non_exhaustive]
pub enum LuaError {
Show 25 variants
SyntaxError {
message: String,
incomplete_input: bool,
},
RuntimeError(String),
MemoryError(String),
SafetyError(String),
MemoryLimitNotAvailable,
MainThreadNotAvailable,
RecursiveMutCallback,
CallbackDestructed,
StackError,
BindError,
ToLuaConversionError {
from: &'static str,
to: &'static str,
message: Option<String>,
},
FromLuaConversionError {
from: &'static str,
to: &'static str,
message: Option<String>,
},
CoroutineInactive,
UserDataTypeMismatch,
UserDataDestructed,
UserDataBorrowError,
UserDataBorrowMutError,
MetaMethodRestricted(String),
MetaMethodTypeError {
method: String,
type_name: &'static str,
message: Option<String>,
},
MismatchedRegistryKey,
CallbackError {
traceback: String,
cause: Arc<Error>,
},
PreviouslyResumedPanic,
SerializeError(String),
DeserializeError(String),
ExternalError(Arc<dyn Error + Sync + Send + 'static>),
}
Expand description
Error type returned by mlua
methods.
Variants (Non-exhaustive)
This enum is marked as non-exhaustive
SyntaxError
Fields
message: String
The error message as returned by Lua.
incomplete_input: bool
true
if the error can likely be fixed by appending more input to the source code.
This is useful for implementing REPLs as they can query the user for more input if this is set.
Syntax error while parsing Lua source code.
RuntimeError(String)
Lua runtime error, aka LUA_ERRRUN
.
The Lua VM returns this error when a builtin operation is performed on incompatible types.
Among other things, this includes invoking operators on wrong types (such as calling or
indexing a nil
value).
MemoryError(String)
Lua memory error, aka LUA_ERRMEM
The Lua VM returns this error when the allocator does not return the requested memory, aka it is an out-of-memory error.
SafetyError(String)
Potentially unsafe action in safe mode.
MemoryLimitNotAvailable
Setting memory limit is not available.
This error can only happen when Lua state was not created by us and does not have the custom allocator attached.
MainThreadNotAvailable
Main thread is not available.
This error can only happen in Lua5.1/LuaJIT module mode, when module loaded within a coroutine.
These Lua versions does not have LUA_RIDX_MAINTHREAD
registry key.
RecursiveMutCallback
A mutable callback has triggered Lua code that has called the same mutable callback again.
This is an error because a mutable callback can only be borrowed mutably once.
CallbackDestructed
Either a callback or a userdata method has been called, but the callback or userdata has been destructed.
This can happen either due to to being destructed in a previous __gc, or due to being
destructed from exiting a Lua::scope
call.
StackError
Not enough stack space to place arguments to Lua functions or return values from callbacks.
Due to the way mlua
works, it should not be directly possible to run out of stack space
during normal use. The only way that this error can be triggered is if a Function
is
called with a huge number of arguments, or a rust callback returns a huge number of return
values.
BindError
Too many arguments to Function::bind
ToLuaConversionError
Fields
from: &'static str
Name of the Rust type that could not be converted.
to: &'static str
Name of the Lua type that could not be created.
A Rust value could not be converted to a Lua value.
FromLuaConversionError
Fields
from: &'static str
Name of the Lua type that could not be converted.
to: &'static str
Name of the Rust type that could not be created.
A Lua value could not be converted to the expected Rust type.
CoroutineInactive
Thread::resume
was called on an inactive coroutine.
A coroutine is inactive if its main function has returned or if an error has occurred inside the coroutine.
Thread::status
can be used to check if the coroutine can be resumed without causing this
error.
UserDataTypeMismatch
An AnyUserData
is not the expected type in a borrow.
This error can only happen when manually using AnyUserData
, or when implementing
metamethods for binary operators. Refer to the documentation of UserDataMethods
for
details.
UserDataDestructed
An AnyUserData
borrow failed because it has been destructed.
This error can happen either due to to being destructed in a previous __gc, or due to being
destructed from exiting a Lua::scope
call.
UserDataBorrowError
An AnyUserData
immutable borrow failed because it is already borrowed mutably.
This error can occur when a method on a UserData
type calls back into Lua, which then
tries to call a method on the same UserData
type. Consider restructuring your API to
prevent these errors.
UserDataBorrowMutError
An AnyUserData
mutable borrow failed because it is already borrowed.
This error can occur when a method on a UserData
type calls back into Lua, which then
tries to call a method on the same UserData
type. Consider restructuring your API to
prevent these errors.
MetaMethodRestricted(String)
A MetaMethod
operation is restricted (typically for __gc
or __metatable
).
MetaMethodTypeError
A MetaMethod
(eg. __index
or __newindex
) has invalid type.
MismatchedRegistryKey
A RegistryKey
produced from a different Lua state was used.
CallbackError
Fields
traceback: String
Lua call stack backtrace.
A Rust callback returned Err
, raising the contained Error
as a Lua error.
PreviouslyResumedPanic
A Rust panic that was previously resumed, returned again.
This error can occur only when a Rust panic resumed previously was recovered and returned again.
SerializeError(String)
Serialization error.
DeserializeError(String)
Deserialization error.
ExternalError(Arc<dyn Error + Sync + Send + 'static>)
A custom error.
This can be used for returning user-defined errors from callbacks.
Returning Err(ExternalError(...))
from a Rust callback will raise the error as a Lua
error. The Rust code that originally invoked the Lua code then receives a CallbackError
,
from which the original error (and a stack traceback) can be recovered.
Implementations
Trait Implementations
sourceimpl Error for Error
impl Error for Error
sourcefn custom<T>(msg: T) -> Errorwhere
T: Display,
fn custom<T>(msg: T) -> Errorwhere
T: Display,
sourcefn invalid_type(unexp: Unexpected<'_>, exp: &dyn Expected) -> Self
fn invalid_type(unexp: Unexpected<'_>, exp: &dyn Expected) -> Self
Deserialize
receives a type different from what it was
expecting. Read moresourcefn invalid_value(unexp: Unexpected<'_>, exp: &dyn Expected) -> Self
fn invalid_value(unexp: Unexpected<'_>, exp: &dyn Expected) -> Self
Deserialize
receives a value of the right type but that
is wrong for some other reason. Read moresourcefn invalid_length(len: usize, exp: &dyn Expected) -> Self
fn invalid_length(len: usize, exp: &dyn Expected) -> Self
sourcefn unknown_variant(variant: &str, expected: &'static [&'static str]) -> Self
fn unknown_variant(variant: &str, expected: &'static [&'static str]) -> Self
Deserialize
enum type received a variant with an
unrecognized name. Read moresourcefn unknown_field(field: &str, expected: &'static [&'static str]) -> Self
fn unknown_field(field: &str, expected: &'static [&'static str]) -> Self
Deserialize
struct type received a field with an
unrecognized name. Read moresourcefn missing_field(field: &'static str) -> Self
fn missing_field(field: &'static str) -> Self
Deserialize
struct type expected to receive a required
field with a particular name but that field was not present in the
input. Read moresourcefn duplicate_field(field: &'static str) -> Self
fn duplicate_field(field: &'static str) -> Self
Deserialize
struct type received more than one of the
same field. Read more