1use std::fmt;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
10pub enum PluginError {
11 IllegalName(String),
13 Duplicate(String),
15 UnknownDep(String),
17 DepCycle(Vec<String>),
19 UnknownName(String),
21 Stopped,
23}
24
25impl fmt::Display for PluginError {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 match self {
28 Self::IllegalName(n) => write!(f, "illegal plugin name: {n:?}"),
29 Self::Duplicate(n) => write!(f, "duplicate plugin: {n:?}"),
30 Self::UnknownDep(n) => write!(f, "unknown dependency at start: {n:?}"),
31 Self::DepCycle(c) => write!(f, "dependency cycle: {c:?}"),
32 Self::UnknownName(n) => write!(f, "unknown plugin: {n:?}"),
33 Self::Stopped => write!(f, "host closed"),
34 }
35 }
36}
37impl std::error::Error for PluginError {}
38
39#[derive(Debug, Clone, PartialEq, Eq)]
41pub enum AskError {
42 Timeout { target: String, pending: u64 },
48 TargetGone { target: String },
50 UnknownService { service: String },
52 InvalidPayload { target: String },
54 BusStopped,
56}
57
58impl fmt::Display for AskError {
59 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60 match self {
61 Self::Timeout { target, pending } => {
62 if *pending == 0 {
63 write!(f, "ask timeout: {target}")
64 } else {
65 write!(f, "ask timeout: {target}(目标积压 {pending} 帧)")
66 }
67 }
68 Self::TargetGone { target } => write!(f, "ask target gone: {target}"),
69 Self::UnknownService { service } => write!(f, "unknown service: {service}"),
70 Self::InvalidPayload { target } => write!(f, "ask invalid payload/contract: {target}"),
71 Self::BusStopped => write!(f, "bus stopped"),
72 }
73 }
74}
75impl std::error::Error for AskError {}