use vox_core::SessionError;
#[derive(Debug)]
pub enum ServeError {
Io(std::io::Error),
AddrInUse { addr: String },
LockHeldUnhealthy { addr: String },
UnsupportedScheme { scheme: String },
Session(SessionError),
}
impl std::fmt::Display for ServeError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Io(e) => write!(f, "io error: {e}"),
Self::AddrInUse { addr } => {
write!(f, "another healthy process is already serving on {addr}")
}
Self::LockHeldUnhealthy { addr } => write!(
f,
"another process holds the lock on {addr} but is not responding"
),
Self::UnsupportedScheme { scheme } => {
write!(f, "unsupported transport scheme: {scheme:?}")
}
Self::Session(e) => write!(f, "{e}"),
}
}
}
impl std::error::Error for ServeError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Io(e) => Some(e),
Self::Session(e) => Some(e),
_ => None,
}
}
}
impl From<std::io::Error> for ServeError {
fn from(e: std::io::Error) -> Self {
Self::Io(e)
}
}
impl From<SessionError> for ServeError {
fn from(e: SessionError) -> Self {
Self::Session(e)
}
}