zoe_message_store/
error.rs

1use thiserror::Error;
2use zoe_wire_protocol::MessageError;
3
4#[derive(Error, Debug)]
5pub enum MessageStoreError {
6    #[error("Redis error: {0}")]
7    Redis(#[from] redis::RedisError),
8
9    #[error("Serialization error: {0}")]
10    Serialization(String),
11
12    #[error("Internal error: {0}")]
13    Internal(String),
14
15    #[error("Empty filters")]
16    EmptyFilters,
17}
18
19impl From<std::io::Error> for MessageStoreError {
20    fn from(err: std::io::Error) -> Self {
21        MessageStoreError::Internal(err.to_string())
22    }
23}
24
25impl From<Box<dyn std::error::Error>> for MessageStoreError {
26    fn from(err: Box<dyn std::error::Error>) -> Self {
27        MessageStoreError::Internal(err.to_string())
28    }
29}
30
31impl From<hex::FromHexError> for MessageStoreError {
32    fn from(err: hex::FromHexError) -> Self {
33        MessageStoreError::Serialization(err.to_string())
34    }
35}
36
37impl From<std::time::SystemTimeError> for MessageStoreError {
38    fn from(err: std::time::SystemTimeError) -> Self {
39        MessageStoreError::Internal(err.to_string())
40    }
41}
42
43impl From<MessageStoreError> for MessageError {
44    fn from(err: MessageStoreError) -> Self {
45        match err {
46            MessageStoreError::Redis(e) => MessageError::StorageError {
47                message: e.to_string(),
48            },
49            MessageStoreError::Serialization(e) => MessageError::InternalError { message: e },
50            MessageStoreError::EmptyFilters => MessageError::InternalError {
51                message: "Empty filters".to_string(),
52            },
53            MessageStoreError::Internal(e) => MessageError::InternalError { message: e },
54        }
55    }
56}
57
58pub type Result<T> = std::result::Result<T, MessageStoreError>;