Enum mlua::Error

source ·
#[non_exhaustive]
pub enum Error {
Show 27 variants SyntaxError { message: String, incomplete_input: bool, }, RuntimeError(String), MemoryError(String), GarbageCollectorError(String), SafetyError(String), MemoryLimitNotAvailable, RecursiveMutCallback, CallbackDestructed, StackError, BindError, BadArgument { to: Option<String>, pos: usize, name: Option<String>, cause: Arc<Error>, }, 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 StdError + Send + Sync>), WithContext { context: String, cause: Arc<Error>, },
}
Expand description

Error type returned by mlua methods.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

SyntaxError

Syntax error while parsing Lua source code.

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.

§

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.

§

GarbageCollectorError(String)

Available on crate features lua53 or lua52 only.

Lua garbage collector error, aka LUA_ERRGCMM.

The Lua VM returns this error when there is an error running a __gc metamethod.

§

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.

§

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.

§

BadArgument

Bad argument received from Lua (usually when calling a function).

This error can help to identify the argument that caused the error (which is stored in the corresponding field).

Fields

§to: Option<String>

Function that was called.

§pos: usize

Argument position (usually starts from 1).

§name: Option<String>

Argument name.

§cause: Arc<Error>

Underlying error returned when converting argument to a Lua value.

§

ToLuaConversionError

A Rust value could not be converted to a Lua value.

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.

§message: Option<String>

A message indicating why the conversion failed in more detail.

§

FromLuaConversionError

A Lua value could not be converted to the expected Rust type.

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.

§message: Option<String>

A string containing more detailed error information.

§

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.

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.

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.

Fields

§method: String

Name of the metamethod.

§type_name: &'static str

Passed value type.

§message: Option<String>

A string containing more detailed error information.

§

MismatchedRegistryKey

A RegistryKey produced from a different Lua state was used.

§

CallbackError

A Rust callback returned Err, raising the contained Error as a Lua error.

Fields

§traceback: String

Lua call stack backtrace.

§cause: Arc<Error>

Original error returned by the Rust code.

§

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)

Available on crate feature serialize only.

Serialization error.

§

DeserializeError(String)

Available on crate feature serialize only.

Deserialization error.

§

ExternalError(Arc<dyn StdError + Send + Sync>)

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.

§

WithContext

An error with additional context.

Fields

§context: String

A string containing additional context.

§cause: Arc<Error>

Underlying error.

Implementations§

source§

impl Error

source

pub fn runtime<S: Display>(message: S) -> Self

Creates a new RuntimeError with the given message.

source

pub fn external<T: Into<Box<dyn StdError + Send + Sync>>>(err: T) -> Self

Wraps an external error object.

source

pub fn downcast_ref<T>(&self) -> Option<&T>
where T: StdError + 'static,

Attempts to downcast the external error object to a concrete type by reference.

Trait Implementations§

source§

impl Clone for Error

source§

fn clone(&self) -> Error

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Error

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Error

source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Error for Error

source§

fn custom<T: Display>(msg: T) -> Self

Used when a Serialize implementation encounters any error while serializing a type. Read more
source§

impl Error for Error

source§

fn source(&self) -> Option<&(dyn StdError + 'static)>

The lower-level source of this error, if any. Read more
1.0.0 · source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type based access to context intended for error reports. Read more
source§

impl Error for Error

source§

fn custom<T: Display>(msg: T) -> Self

Raised when there is general error when deserializing a type. Read more
source§

fn invalid_type(unexp: Unexpected<'_>, exp: &dyn Expected) -> Self

Raised when a Deserialize receives a type different from what it was expecting. Read more
source§

fn invalid_value(unexp: Unexpected<'_>, exp: &dyn Expected) -> Self

Raised when a Deserialize receives a value of the right type but that is wrong for some other reason. Read more
source§

fn invalid_length(len: usize, exp: &dyn Expected) -> Self

Raised when deserializing a sequence or map and the input data contains too many or too few elements. Read more
source§

fn unknown_variant(variant: &str, expected: &'static [&'static str]) -> Self

Raised when a Deserialize enum type received a variant with an unrecognized name.
source§

fn unknown_field(field: &str, expected: &'static [&'static str]) -> Self

Raised when a Deserialize struct type received a field with an unrecognized name.
source§

fn missing_field(field: &'static str) -> Self

Raised when a Deserialize struct type expected to receive a required field with a particular name but that field was not present in the input.
source§

fn duplicate_field(field: &'static str) -> Self

Raised when a Deserialize struct type received more than one of the same field.
source§

impl ErrorContext for Error

source§

fn context<C: Display>(self, context: C) -> Self

Wraps the error value with additional context.
source§

fn with_context<C: Display>(self, f: impl FnOnce(&Error) -> C) -> Self

Wrap the error value with additional context that is evaluated lazily only once an error does occur.
source§

impl From<AddrParseError> for Error

source§

fn from(err: AddrParseError) -> Self

Converts to this type from the input type.
source§

impl From<Error> for Error

source§

fn from(err: IoError) -> Self

Converts to this type from the input type.
source§

impl From<Utf8Error> for Error

source§

fn from(err: Utf8Error) -> Self

Converts to this type from the input type.
source§

impl<'lua> FromLua<'lua> for Error

source§

fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result<Error>

Performs the conversion.
source§

impl<'lua> IntoLua<'lua> for Error

source§

fn into_lua(self, _: &'lua Lua) -> Result<Value<'lua>>

Performs the conversion.

Auto Trait Implementations§

§

impl Freeze for Error

§

impl !RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl !UnwindSafe for Error

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<E> ExternalError for E
where E: Into<Box<dyn Error + Send + Sync>>,

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<'lua, T> FromLuaMulti<'lua> for T
where T: FromLua<'lua>,

source§

fn from_lua_multi(values: MultiValue<'lua>, lua: &'lua Lua) -> Result<T, Error>

Performs the conversion. Read more
source§

fn from_lua_args( args: MultiValue<'lua>, i: usize, to: Option<&str>, lua: &'lua Lua ) -> Result<T, Error>

source§

unsafe fn from_stack_multi(nvals: i32, lua: &'lua Lua) -> Result<T, Error>

source§

unsafe fn from_stack_args( nargs: i32, i: usize, to: Option<&str>, lua: &'lua Lua ) -> Result<T, Error>

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<'lua, T> IntoLuaMulti<'lua> for T
where T: IntoLua<'lua>,

source§

fn into_lua_multi(self, lua: &'lua Lua) -> Result<MultiValue<'lua>, Error>

Performs the conversion.
source§

unsafe fn push_into_stack_multi(self, lua: &'lua Lua) -> Result<i32, Error>

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.