use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PluginError {
IllegalName(String),
Duplicate(String),
UnknownDep(String),
DepCycle(Vec<String>),
UnknownName(String),
Stopped,
}
impl fmt::Display for PluginError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::IllegalName(n) => write!(f, "illegal plugin name: {n:?}"),
Self::Duplicate(n) => write!(f, "duplicate plugin: {n:?}"),
Self::UnknownDep(n) => write!(f, "unknown dependency at start: {n:?}"),
Self::DepCycle(c) => write!(f, "dependency cycle: {c:?}"),
Self::UnknownName(n) => write!(f, "unknown plugin: {n:?}"),
Self::Stopped => write!(f, "host closed"),
}
}
}
impl std::error::Error for PluginError {}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AskError {
Timeout { target: String, pending: u64 },
TargetGone { target: String },
UnknownService { service: String },
InvalidPayload { target: String },
BusStopped,
}
impl fmt::Display for AskError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Timeout { target, pending } => {
if *pending == 0 {
write!(f, "ask timeout: {target}")
} else {
write!(f, "ask timeout: {target}(目标积压 {pending} 帧)")
}
}
Self::TargetGone { target } => write!(f, "ask target gone: {target}"),
Self::UnknownService { service } => write!(f, "unknown service: {service}"),
Self::InvalidPayload { target } => write!(f, "ask invalid payload/contract: {target}"),
Self::BusStopped => write!(f, "bus stopped"),
}
}
}
impl std::error::Error for AskError {}