#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("lua error: {0}")]
Lua(#[from] mlua::Error),
#[error("configuration error: {0}")]
Config(String),
#[error("script error: {0}")]
Script(String),
#[error("i/o error: {0}")]
Io(#[from] std::io::Error),
#[error("http error: {0}")]
Http(#[from] http::Error),
#[error("handler execution timed out")]
Timeout,
#[error("no Lua state available within the pool wait budget")]
PoolBusy,
#[error("panic while handling the request: {0}")]
Panic(String),
#[error("shutdown drain deadline expired with requests still in flight")]
ShutdownTimeout,
}
impl Error {
pub fn poisons_state(&self) -> bool {
match self {
Error::Panic(_) => true,
Error::Lua(err) => is_memory_error(err),
_ => false,
}
}
}
fn is_memory_error(err: &mlua::Error) -> bool {
match err {
mlua::Error::MemoryError(_) => true,
mlua::Error::CallbackError { cause, .. } => is_memory_error(cause),
mlua::Error::WithContext { cause, .. } => is_memory_error(cause),
_ => false,
}
}
pub type Result<T = (), E = Error> = std::result::Result<T, E>;
mod info;
mod render;
#[cfg(test)]
mod tests;
pub(crate) use info::EXEC_BUDGET_MSG;
pub use info::ErrorInfo;
pub use render::{message_token, source_snippet};