Skip to main content

tightbeam/colony/hive/
error.rs

1//! Hive-specific error types
2
3use crate::transport::error::TransportError;
4use crate::{Errorizable, TightBeamError};
5
6/// Errors specific to hives
7///
8/// Failure modes are distinct variants (not string payloads) so callers
9/// can branch on them, and wrapper variants preserve their cause chain
10/// through [`core::error::Error::source`].
11#[derive(Errorizable, Debug)]
12pub enum HiveError {
13	/// Invalid servlet ID
14	#[error("Invalid servlet ID: {:#?}")]
15	InvalidServletId(Vec<u8>),
16
17	/// Transport/IO error
18	#[error("IO error: {0}")]
19	#[from]
20	#[source]
21	Io(std::io::Error),
22
23	/// Transport-level failure while communicating with a cluster/servlet
24	#[error("Transport error: {0}")]
25	#[from]
26	#[source]
27	Transport(TransportError),
28
29	/// Frame encode/decode/build/sign failure
30	#[error("Frame error: {0}")]
31	#[source]
32	Frame(Box<TightBeamError>),
33
34	/// Message emission failed
35	#[error("Message emission failed")]
36	EmitFailed,
37
38	/// No response received
39	#[error("No response received")]
40	NoResponse,
41
42	/// Message decoding failed
43	#[error("Message decoding failed")]
44	DecodeFailed,
45
46	/// Lock poisoned
47	#[error("Lock poisoned")]
48	LockPoisoned,
49
50	/// No trusted keys configured for ClusterSecurityGate
51	#[error("No trusted keys configured")]
52	NoTrustedKeys,
53}
54
55impl<T> From<std::sync::PoisonError<T>> for HiveError {
56	fn from(_: std::sync::PoisonError<T>) -> Self {
57		HiveError::LockPoisoned
58	}
59}
60
61// Boxed manually: `TightBeamError` embeds `HiveError`, so the unboxed
62// wrapper would be infinitely sized.
63impl From<TightBeamError> for HiveError {
64	fn from(e: TightBeamError) -> Self {
65		HiveError::Frame(Box::new(e))
66	}
67}