Skip to main content

oxigdal_cache_advanced/
error.rs

1//! Error types for cache operations
2
3use std::io;
4
5/// Result type for cache operations
6pub type Result<T> = std::result::Result<T, CacheError>;
7
8/// Errors that can occur during cache operations
9#[derive(Debug, thiserror::Error)]
10pub enum CacheError {
11    /// I/O error occurred
12    #[error("I/O error: {0}")]
13    Io(#[from] io::Error),
14
15    /// Serialization error
16    #[error("Serialization error: {0}")]
17    Serialization(String),
18
19    /// Deserialization error
20    #[error("Deserialization error: {0}")]
21    Deserialization(String),
22
23    /// Compression error
24    #[error("Compression error: {0}")]
25    Compression(String),
26
27    /// Decompression error
28    #[error("Decompression error: {0}")]
29    Decompression(String),
30
31    /// Cache full error
32    #[error("Cache tier is full: {0}")]
33    CacheFull(String),
34
35    /// Key not found
36    #[error("Key not found: {0}")]
37    KeyNotFound(String),
38
39    /// Invalid configuration
40    #[error("Invalid configuration: {0}")]
41    InvalidConfig(String),
42
43    /// Network error for distributed cache
44    #[error("Network error: {0}")]
45    Network(String),
46
47    /// Timeout error
48    #[error("Operation timed out")]
49    Timeout,
50
51    /// Prediction error
52    #[error("Prediction error: {0}")]
53    Prediction(String),
54
55    /// Analytics error
56    #[error("Analytics error: {0}")]
57    Analytics(String),
58
59    /// Lock error
60    #[error("Lock acquisition failed")]
61    LockError,
62
63    /// Generic error
64    #[error("Cache error: {0}")]
65    Other(String),
66}
67
68impl From<serde_json::Error> for CacheError {
69    fn from(err: serde_json::Error) -> Self {
70        CacheError::Serialization(err.to_string())
71    }
72}
73
74impl From<Box<dyn std::error::Error + Send + Sync>> for CacheError {
75    fn from(err: Box<dyn std::error::Error + Send + Sync>) -> Self {
76        CacheError::Other(err.to_string())
77    }
78}