threatflux_cache/
error.rs1use std::io;
4use thiserror::Error;
5
6#[derive(Error, Debug)]
8pub enum CacheError {
9 #[error("I/O error: {0}")]
11 Io(#[from] io::Error),
12
13 #[error("Serialization error: {0}")]
15 Serialization(String),
16
17 #[error("Deserialization error: {0}")]
19 Deserialization(String),
20
21 #[error("Cache capacity exceeded: {message}")]
23 CapacityExceeded {
24 message: String,
26 },
27
28 #[error("Storage backend error: {0}")]
30 StorageBackend(String),
31
32 #[error("Entry not found for key")]
34 NotFound,
35
36 #[error("Invalid configuration: {0}")]
38 InvalidConfiguration(String),
39
40 #[cfg(feature = "compression")]
42 #[error("Compression error: {0}")]
43 Compression(String),
44
45 #[error("Custom error: {0}")]
47 Custom(String),
48}
49
50pub type Result<T> = std::result::Result<T, CacheError>;
52
53#[cfg(feature = "json-serialization")]
55impl From<serde_json::Error> for CacheError {
56 fn from(err: serde_json::Error) -> Self {
57 if err.is_data() || err.is_eof() {
58 CacheError::Deserialization(err.to_string())
59 } else {
60 CacheError::Serialization(err.to_string())
61 }
62 }
63}
64
65#[cfg(feature = "bincode-serialization")]
66impl From<bincode::Error> for CacheError {
67 fn from(err: bincode::Error) -> Self {
68 CacheError::Serialization(err.to_string())
69 }
70}