1use thiserror::Error;
2
3#[derive(Debug, Error)]
5#[error("error")]
6pub enum Error {
7 #[error("Failed to join cluster")]
9 ClusterJoinFailed,
10
11 #[error("Failed to initialize cluster")]
13 ClusterInitFailed,
14
15 #[error("Invalid node address")]
17 InvalidAddress,
18
19 #[error("Failed to start RPC server")]
21 RPCBindFailed(tonic::transport::Error),
22
23 #[error("Failed to create data directory")]
25 DataDirectoryCreateFailed(std::io::Error),
26
27 #[error("Failed to open sled database")]
29 SledError(sled::Error),
30
31 #[error("Client failed to connect")]
33 ClientConnectFailed,
34
35 #[error("RPC client call failed")]
37 RPCCallFailed,
38
39 #[error("Deserialize failed")]
41 DeserializeFailed,
42
43 #[error("Serialize failed")]
45 SerializeFailed(bincode::Error),
46
47 #[error("Insert failed")]
49 InsertFailed,
50
51 #[error("Missing cluster configuration")]
53 MissingClusterConfig,
54
55 #[error("Peer not found")]
57 PeerNotFound,
58
59 #[error("Failed to connect to peer")]
61 PeerConnectFailed,
62
63 #[error("Subscriber stream closed")]
65 StreamClosed,
66
67 #[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}