summaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs51
1 files changed, 26 insertions, 25 deletions
diff --git a/src/error.rs b/src/error.rs
index a9a52c1..ac9363d 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,16 +1,16 @@
+use std::error::Error as StdError;
use std::fmt;
use std::result::Result as StdResult;
+use std::string::String as StdString;
use std::sync::Arc;
-use failure;
-
/// Error type returned by `rlua` methods.
#[derive(Debug, Clone)]
pub enum Error {
/// Syntax error while parsing Lua source code.
SyntaxError {
/// The error message as returned by Lua.
- message: String,
+ message: StdString,
/// `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
@@ -22,11 +22,16 @@ pub enum Error {
/// 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).
- RuntimeError(String),
+ RuntimeError(StdString),
+ /// 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.
+ MemoryError(StdString),
/// Lua garbage collector error, aka `LUA_ERRGCMM`.
///
/// The Lua VM returns this error when there is an error running a `__gc` metamethod.
- GarbageCollectorError(String),
+ GarbageCollectorError(StdString),
/// 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.
@@ -53,7 +58,7 @@ pub enum Error {
/// Name of the Lua type that could not be created.
to: &'static str,
/// A message indicating why the conversion failed in more detail.
- message: Option<String>,
+ message: Option<StdString>,
},
/// A Lua value could not be converted to the expected Rust type.
FromLuaConversionError {
@@ -62,7 +67,7 @@ pub enum Error {
/// Name of the Rust type that could not be created.
to: &'static str,
/// A string containing more detailed error information.
- message: Option<String>,
+ message: Option<StdString>,
},
/// [`Thread::resume`] was called on an inactive coroutine.
///
@@ -107,7 +112,7 @@ pub enum Error {
/// A Rust callback returned `Err`, raising the contained `Error` as a Lua error.
CallbackError {
/// Lua call stack backtrace.
- traceback: String,
+ traceback: StdString,
/// Original error returned by the Rust code.
cause: Arc<Error>,
},
@@ -118,7 +123,7 @@ pub enum Error {
/// 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.
- ExternalError(Arc<failure::Error>),
+ ExternalError(Arc<dyn StdError + Send + Sync>),
}
/// A specialized `Result` type used by `rlua`'s API.
@@ -129,6 +134,9 @@ impl fmt::Display for Error {
match *self {
Error::SyntaxError { ref message, .. } => write!(fmt, "syntax error: {}", message),
Error::RuntimeError(ref msg) => write!(fmt, "runtime error: {}", msg),
+ Error::MemoryError(ref msg) => {
+ write!(fmt, "memory error: {}", msg)
+ }
Error::GarbageCollectorError(ref msg) => {
write!(fmt, "garbage collector error: {}", msg)
}
@@ -174,34 +182,27 @@ impl fmt::Display for Error {
Error::MismatchedRegistryKey => {
write!(fmt, "RegistryKey used from different Lua state")
}
- Error::CallbackError { ref traceback, .. } => {
- write!(fmt, "callback error: {}", traceback)
+ Error::CallbackError { ref traceback, ref cause } => {
+ write!(fmt, "callback error: {}: {}", cause, traceback)
}
- Error::ExternalError(ref err) => err.fmt(fmt),
+ Error::ExternalError(ref err) => write!(fmt, "external error: {}", err),
}
}
}
-impl failure::Fail for Error {
- fn cause(&self) -> Option<&dyn failure::Fail> {
+impl StdError for Error {
+ fn source(&self) -> Option<&(dyn StdError + 'static)> {
match *self {
Error::CallbackError { ref cause, .. } => Some(cause.as_ref()),
- Error::ExternalError(ref err) => err.as_fail().cause(),
- _ => None,
- }
- }
-
- fn backtrace(&self) -> Option<&failure::Backtrace> {
- match *self {
- Error::ExternalError(ref err) => Some(err.backtrace()),
+ Error::ExternalError(ref err) => Some(err.as_ref()),
_ => None,
}
}
}
impl Error {
- pub fn external<T: Into<failure::Error>>(err: T) -> Error {
- Error::ExternalError(Arc::new(err.into()))
+ pub fn external<T: Into<Box<dyn StdError + Send + Sync>>>(err: T) -> Error {
+ Error::ExternalError(err.into().into())
}
}
@@ -211,7 +212,7 @@ pub trait ExternalError {
impl<E> ExternalError for E
where
- E: Into<failure::Error>,
+ E: Into<Box<dyn StdError + Send + Sync>>,
{
fn to_lua_err(self) -> Error {
Error::external(self)