Skip to main content

halephant_core/errors/
mod.rs

1#[derive(Debug, thiserror::Error)]
2pub enum ConfigError {
3    #[error("failed to read config file: {0}")]
4    Io(#[from] std::io::Error),
5
6    #[error("failed to parse config: {0}")]
7    Parse(#[from] toml::de::Error),
8
9    #[error("{0}")]
10    Validation(String),
11}
12
13/// Error type for wire protocol parsing.
14#[derive(Debug, thiserror::Error)]
15pub enum ProtocolError {
16    #[error("unknown message type: {0:#04x}")]
17    UnknownMessageType(u8),
18
19    #[error("{message} (at byte {position})")]
20    InvalidValue { position: usize, message: String },
21
22    #[error(transparent)]
23    Io(#[from] std::io::Error),
24}
25
26#[derive(Debug, thiserror::Error)]
27pub enum AuthError {
28    #[error("authentication rejected for {user:?} on {database:?}")]
29    Rejected { database: String, user: String },
30
31    #[error("invalid credentials")]
32    InvalidCredentials,
33
34    #[error("failed to fetch verifier: {0}")]
35    VerifierFetch(String),
36
37    #[error("protocol error: {0}")]
38    Protocol(String),
39
40    #[error("I/O error: {0}")]
41    Io(#[from] std::io::Error),
42
43    #[error("wire protocol error: {0}")]
44    Wire(#[from] ProtocolError),
45}
46
47#[derive(Debug, thiserror::Error)]
48pub enum ResolveError {
49    #[error("database {database:?} is not configured in any cluster")]
50    UnknownDatabase { database: String },
51
52    #[error("no primary discovered for cluster {cluster:?}")]
53    NoPrimary { cluster: String },
54
55    #[error("no healthy replica available for cluster {cluster:?}")]
56    NoReplica { cluster: String },
57}