Remove ErrorError

This commit is contained in:
Jonas Schievink 2017-08-02 14:01:00 +02:00
parent a43bfd8f63
commit 70f05ac068
2 changed files with 6 additions and 8 deletions

View File

@ -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",

View File

@ -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