tightbeam/colony/cluster/
error.rs1pub const NO_RESPONSE_MSG: &[u8] = b"no response";
5
6pub const TRANSPORT_ERROR_MSG: &[u8] = b"transport error";
8
9#[cfg_attr(feature = "derive", derive(crate::Errorizable))]
11#[derive(Debug, Clone, PartialEq, Eq)]
12pub enum ClusterError {
13 #[cfg_attr(feature = "derive", error("Lock poisoned"))]
15 LockPoisoned,
16 #[cfg_attr(feature = "derive", error("Unknown servlet type: {:#?}"))]
18 UnknownServletType(Vec<u8>),
19 #[cfg_attr(feature = "derive", error("No hives available for servlet type: {:#?}"))]
21 NoHivesAvailable(Vec<u8>),
22 #[cfg_attr(feature = "derive", error("Hive communication failed: {:#?}"))]
24 HiveCommunicationFailed(Vec<u8>),
25 #[cfg_attr(feature = "derive", error("Registration failed"))]
27 RegistrationFailed,
28 #[cfg_attr(feature = "derive", error("Frame encoding error"))]
30 EncodingError,
31 #[cfg_attr(feature = "derive", error("Frame signing error"))]
33 SigningError,
34 #[cfg_attr(feature = "derive", error("Invalid address: {:#?}"))]
36 InvalidAddress(Vec<u8>),
37}
38
39#[cfg(not(feature = "derive"))]
40impl core::fmt::Display for ClusterError {
41 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
42 match self {
43 ClusterError::LockPoisoned => write!(f, "Lock poisoned"),
44 ClusterError::UnknownServletType(t) => {
45 write!(f, "Unknown servlet type: {}", String::from_utf8_lossy(t))
46 }
47 ClusterError::NoHivesAvailable(t) => {
48 write!(f, "No hives available for servlet type: {}", String::from_utf8_lossy(t))
49 }
50 ClusterError::HiveCommunicationFailed(msg) => {
51 write!(f, "Hive communication failed: {}", String::from_utf8_lossy(msg))
52 }
53 ClusterError::RegistrationFailed => write!(f, "Registration failed"),
54 ClusterError::EncodingError => write!(f, "Frame encoding error"),
55 ClusterError::SigningError => write!(f, "Frame signing error"),
56 ClusterError::InvalidAddress(addr) => {
57 write!(f, "Invalid address: {}", String::from_utf8_lossy(addr))
58 }
59 }
60 }
61}
62
63#[cfg(not(feature = "derive"))]
64impl core::error::Error for ClusterError {}
65
66impl<T> From<std::sync::PoisonError<T>> for ClusterError {
67 fn from(_: std::sync::PoisonError<T>) -> Self {
68 ClusterError::LockPoisoned
69 }
70}
71
72impl From<crate::transport::error::TransportError> for ClusterError {
73 fn from(_: crate::transport::error::TransportError) -> Self {
74 ClusterError::HiveCommunicationFailed(TRANSPORT_ERROR_MSG.to_vec())
75 }
76}
77
78impl From<crate::TightBeamError> for ClusterError {
79 fn from(_: crate::TightBeamError) -> Self {
80 ClusterError::EncodingError
81 }
82}