1use thiserror::Error;
4
5pub type KVResult<T> = Result<T, KVError>;
7
8#[derive(Error, Debug)]
10pub enum KVError {
11 #[error("Key not found: {0}")]
12 KeyNotFound(String),
13
14 #[error("Invalid key: {0}")]
15 InvalidKey(String),
16
17 #[error("Invalid value: {0}")]
18 InvalidValue(String),
19
20 #[error("TTL error: {0}")]
21 TTL(String),
22
23 #[error("Encryption error: {0}")]
24 Encryption(String),
25
26 #[error("Storage error: {0}")]
27 Storage(String),
28
29 #[error("Serialization error: {0}")]
30 Serialization(#[from] serde_json::Error),
31
32 #[error("IO error: {0}")]
33 Io(#[from] std::io::Error),
34
35 #[error("Configuration error: {0}")]
36 Config(#[from] config::ConfigError),
37
38 #[error("Database error: {0}")]
39 Database(#[from] sled::Error),
40
41 #[error("Authentication error: {0}")]
42 Auth(String),
43
44 #[error("Rate limit exceeded")]
45 RateLimit,
46
47 #[error("Internal error: {0}")]
48 Internal(String),
49}
50
51impl From<&str> for KVError {
52 fn from(msg: &str) -> Self {
53 Self::Internal(msg.to_string())
54 }
55}
56
57impl From<String> for KVError {
58 fn from(msg: String) -> Self {
59 Self::Internal(msg)
60 }
61}