use std::fmt;
use vibe_ready::VibeEngineError;
#[derive(Debug, Clone)]
pub enum NetError {
NotStarted,
EngineCreate(String),
Runtime(String),
Lock,
}
impl NetError {
pub(crate) fn from_poison<T>(_err: std::sync::PoisonError<T>) -> Self {
NetError::Lock
}
}
impl fmt::Display for NetError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
NetError::NotStarted => write!(f, "network monitor is not started"),
NetError::EngineCreate(msg) => write!(f, "create runtime engine failed: {msg}"),
NetError::Runtime(msg) => write!(f, "runtime error: {msg}"),
NetError::Lock => write!(
f,
"internal state lock is poisoned; call shutdown and restart to recover"
),
}
}
}
impl std::error::Error for NetError {}
impl From<VibeEngineError> for NetError {
fn from(err: VibeEngineError) -> Self {
NetError::Runtime(err.to_string())
}
}