use std::fmt;
#[derive(Debug)]
#[non_exhaustive]
pub enum StaticError {
NotFound(String),
Traversal(String),
Io(std::io::Error),
PipelineSetup(String),
}
impl fmt::Display for StaticError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
StaticError::NotFound(path) => write!(f, "not found: {path}"),
StaticError::Traversal(path) => write!(f, "path traversal denied: {path}"),
StaticError::Io(e) => write!(f, "io error: {e}"),
StaticError::PipelineSetup(msg) => write!(f, "pipeline setup failed: {msg}"),
}
}
}
impl std::error::Error for StaticError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
StaticError::Io(e) => Some(e),
_ => None,
}
}
}
impl StaticError {
pub fn user_message(&self) -> &'static str {
match self {
StaticError::NotFound(_) | StaticError::Traversal(_) => "not found",
StaticError::Io(_) | StaticError::PipelineSetup(_) => "internal server error",
}
}
}
impl From<std::io::Error> for StaticError {
fn from(e: std::io::Error) -> Self {
StaticError::Io(e)
}
}