1use std::time::Duration;
4
5#[derive(Debug, thiserror::Error)]
7pub enum CassandraError {
8 #[error("Connection error: {0}")]
10 Connection(String),
11
12 #[error("Authentication failed: {0}")]
14 Authentication(String),
15
16 #[error("Query execution failed: {0}")]
18 Query(String),
19
20 #[error("Row deserialization failed: {0}")]
22 Deserialization(String),
23
24 #[error("Timeout after {duration:?}: {operation}")]
26 Timeout {
27 operation: String,
29 duration: Duration,
31 },
32
33 #[error("Configuration error: {0}")]
35 Config(String),
36
37 #[error("TLS error: {0}")]
39 Tls(String),
40
41 #[error("Lightweight transaction not applied")]
43 LwtNotApplied,
44}
45
46pub type CassandraResult<T> = Result<T, CassandraError>;
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_connection_error_display() {
55 let err = CassandraError::Connection("refused".into());
56 assert_eq!(err.to_string(), "Connection error: refused");
57 }
58
59 #[test]
60 fn test_timeout_error_display() {
61 let err = CassandraError::Timeout {
62 operation: "query".into(),
63 duration: Duration::from_secs(5),
64 };
65 assert!(err.to_string().contains("query"));
66 assert!(err.to_string().contains("5s"));
67 }
68
69 #[test]
70 fn test_lwt_not_applied_is_no_data() {
71 let err = CassandraError::LwtNotApplied;
72 assert_eq!(err.to_string(), "Lightweight transaction not applied");
73 }
74}