From 70f05ac06884c1fe6742f73b103014beae7e4554 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 2 Aug 2017 14:01:00 +0200 Subject: [PATCH] Remove ErrorError --- src/error.rs | 7 ------- src/util.rs | 7 ++++++- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/error.rs b/src/error.rs index 73cfd3f..ec2c95f 100644 --- a/src/error.rs +++ b/src/error.rs @@ -22,11 +22,6 @@ pub enum Error { /// Among other things, this includes invoking operators on wrong types (such as calling or /// indexing a `nil` value). RuntimeError(String), - /// Lua error from inside an error handler, aka `LUA_ERRERR`. - /// - /// To prevent an infinite recursion when invoking an error handler, this error will be returned - /// instead of invoking the error handler. - ErrorError(String), /// A Rust value could not be converted to a Lua value. ToLuaConversionError { /// Name of the Rust type that could not be converted. @@ -108,7 +103,6 @@ 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::ErrorError(ref msg) => write!(fmt, "error in error handler: {}", msg), Error::ToLuaConversionError { from, to, ref message } => { write!(fmt, "error converting {} to Lua {}", from, to)?; match *message { @@ -138,7 +132,6 @@ impl StdError for Error { match *self { Error::SyntaxError { .. } => "syntax error", Error::RuntimeError(_) => "runtime error", - Error::ErrorError(_) => "error inside error handler", Error::ToLuaConversionError { .. } => "conversion error to lua", Error::FromLuaConversionError { .. } => "conversion error from lua", Error::CoroutineInactive => "attempt to resume inactive coroutine", diff --git a/src/util.rs b/src/util.rs index 345db98..e91b955 100644 --- a/src/util.rs +++ b/src/util.rs @@ -287,7 +287,12 @@ pub unsafe fn handle_error(state: *mut ffi::lua_State, err: c_int) -> Result<()> message: err_string, } } - ffi::LUA_ERRERR => Error::ErrorError(err_string), + ffi::LUA_ERRERR => { + // This can only happen when rlua's own message handler raises an error, which + // should never happen unless there's a bug. This would also be dangerous as it + // longjmps over Rust frames. + lua_panic!(state, "message handler raised error: {}", err_string); + } ffi::LUA_ERRMEM => { // This is not impossible to hit, but this library is not set up // to handle this properly. Lua does a longjmp on out of memory