pub const NO_RESPONSE_MSG: &[u8] = b"no response";
pub const TRANSPORT_ERROR_MSG: &[u8] = b"transport error";
#[cfg_attr(feature = "derive", derive(crate::Errorizable))]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ClusterError {
#[cfg_attr(feature = "derive", error("Lock poisoned"))]
LockPoisoned,
#[cfg_attr(feature = "derive", error("Unknown servlet type: {:#?}"))]
UnknownServletType(Vec<u8>),
#[cfg_attr(feature = "derive", error("No hives available for servlet type: {:#?}"))]
NoHivesAvailable(Vec<u8>),
#[cfg_attr(feature = "derive", error("Hive communication failed: {:#?}"))]
HiveCommunicationFailed(Vec<u8>),
#[cfg_attr(feature = "derive", error("Registration failed"))]
RegistrationFailed,
#[cfg_attr(feature = "derive", error("Frame encoding error"))]
EncodingError,
#[cfg_attr(feature = "derive", error("Frame signing error"))]
SigningError,
#[cfg_attr(feature = "derive", error("Invalid address: {:#?}"))]
InvalidAddress(Vec<u8>),
}
#[cfg(not(feature = "derive"))]
impl core::fmt::Display for ClusterError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
ClusterError::LockPoisoned => write!(f, "Lock poisoned"),
ClusterError::UnknownServletType(t) => {
write!(f, "Unknown servlet type: {}", String::from_utf8_lossy(t))
}
ClusterError::NoHivesAvailable(t) => {
write!(f, "No hives available for servlet type: {}", String::from_utf8_lossy(t))
}
ClusterError::HiveCommunicationFailed(msg) => {
write!(f, "Hive communication failed: {}", String::from_utf8_lossy(msg))
}
ClusterError::RegistrationFailed => write!(f, "Registration failed"),
ClusterError::EncodingError => write!(f, "Frame encoding error"),
ClusterError::SigningError => write!(f, "Frame signing error"),
ClusterError::InvalidAddress(addr) => {
write!(f, "Invalid address: {}", String::from_utf8_lossy(addr))
}
}
}
}
#[cfg(not(feature = "derive"))]
impl core::error::Error for ClusterError {}
impl<T> From<std::sync::PoisonError<T>> for ClusterError {
fn from(_: std::sync::PoisonError<T>) -> Self {
ClusterError::LockPoisoned
}
}
impl From<crate::transport::error::TransportError> for ClusterError {
fn from(_: crate::transport::error::TransportError) -> Self {
ClusterError::HiveCommunicationFailed(TRANSPORT_ERROR_MSG.to_vec())
}
}
impl From<crate::TightBeamError> for ClusterError {
fn from(_: crate::TightBeamError) -> Self {
ClusterError::EncodingError
}
}