use std::fmt::{self, Display, Formatter}; #[derive(Debug, Clone, Eq, PartialEq)] pub enum LuaXError { InvalidStart, // used internally NonTableChildren, NonTableAttrs, NeededToken(String), ExpectedVar, ExpectedExpression, UnterminatedStringLiteral, NonJsonType, } impl std::error::Error for LuaXError {} impl Display for LuaXError { fn fmt(&self, f: &mut Formatter) -> fmt::Result { match self { LuaXError::InvalidStart => write!(f, "Invalid start"), LuaXError::NonTableChildren => write!(f, "Children must be tables"), LuaXError::NonTableAttrs => write!(f, "Attrs must be tables"), LuaXError::NeededToken(token) => write!(f, "Needed token: {}", token), LuaXError::ExpectedVar => write!(f, "Expected variable"), LuaXError::ExpectedExpression => write!(f, "Expected expression"), LuaXError::UnterminatedStringLiteral => write!(f, "Unterminated string literal"), LuaXError::NonJsonType => write!(f, "Type cannot be represented in JSON"), } } } #[derive(Debug)] pub enum ReluaxError { LuaX(LuaXError), Lua(mlua::Error), Server(String), } impl std::error::Error for ReluaxError {} impl Display for ReluaxError { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { ReluaxError::LuaX(err) => write!(f, "{}", err), ReluaxError::Lua(err) => write!(f, "{}", err), ReluaxError::Server(err) => write!(f, "{}", err), } } } impl From for ReluaxError { fn from(err: LuaXError) -> Self { ReluaxError::LuaX(err) } } impl From for ReluaxError { fn from(err: mlua::Error) -> Self { ReluaxError::Lua(err) } }