Skip to main content

skiff_rs/
error.rs

1use thiserror::Error;
2
3/// All errors that can be returned by skiff.
4#[derive(Debug, Error)]
5#[error("error")]
6pub enum Error {
7    /// A node failed to register itself with any peer in the cluster.
8    #[error("Failed to join cluster")]
9    ClusterJoinFailed,
10
11    /// The cluster could not be initialized (e.g. sled could not be opened).
12    #[error("Failed to initialize cluster")]
13    ClusterInitFailed,
14
15    /// An address string could not be parsed as a valid IPv4 address.
16    #[error("Invalid node address")]
17    InvalidAddress,
18
19    /// The gRPC server could not bind to the requested address and port.
20    #[error("Failed to start RPC server")]
21    RPCBindFailed(tonic::transport::Error),
22
23    /// The data directory could not be created.
24    #[error("Failed to create data directory")]
25    DataDirectoryCreateFailed(std::io::Error),
26
27    /// A sled database operation failed.
28    #[error("Failed to open sled database")]
29    SledError(sled::Error),
30
31    /// The client could not connect to any node in the cluster address list.
32    #[error("Client failed to connect")]
33    ClientConnectFailed,
34
35    /// A gRPC call to a cluster node returned an error status.
36    #[error("RPC client call failed")]
37    RPCCallFailed,
38
39    /// Stored bytes could not be deserialized into the expected type.
40    #[error("Deserialize failed")]
41    DeserializeFailed,
42
43    /// A value could not be serialized with bincode.
44    #[error("Serialize failed")]
45    SerializeFailed(bincode::Error),
46
47    /// The cluster did not acknowledge an insert within the timeout.
48    #[error("Insert failed")]
49    InsertFailed,
50
51    /// No `Configure` entry was found in the Raft log.
52    #[error("Missing cluster configuration")]
53    MissingClusterConfig,
54
55    /// The requested peer UUID is not in the current cluster configuration.
56    #[error("Peer not found")]
57    PeerNotFound,
58
59    /// A gRPC connection to a peer could not be established.
60    #[error("Failed to connect to peer")]
61    PeerConnectFailed,
62
63    /// The subscription stream was closed by the server.
64    #[error("Subscriber stream closed")]
65    StreamClosed,
66
67    /// No leader was elected within the requested timeout.
68    #[error("Timed out waiting for leader election")]
69    LeaderElectionTimeout,
70}
71
72impl From<tonic::transport::Error> for Error {
73    fn from(err: tonic::transport::Error) -> Self {
74        Self::RPCBindFailed(err)
75    }
76}
77
78impl From<std::io::Error> for Error {
79    fn from(err: std::io::Error) -> Self {
80        Self::DataDirectoryCreateFailed(err)
81    }
82}
83
84impl From<sled::Error> for Error {
85    fn from(err: sled::Error) -> Self {
86        Self::SledError(err)
87    }
88}
89
90impl From<bincode::Error> for Error {
91    fn from(err: bincode::Error) -> Self {
92        Self::SerializeFailed(err)
93    }
94}