1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
use bincode::Error as BincodeError;
use std::{error::Error, fmt, io};

#[derive(Debug)]
pub enum LLMError {
    APIError(String),
    SerializationError(String),
    ReqwestError(reqwest::Error),
    IOError(io::Error),
    Other(String),
}

impl fmt::Display for LLMError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            LLMError::APIError(msg) => write!(f, "API Error: {}", msg),
            LLMError::SerializationError(msg) => write!(f, "Serialization Error: {}", msg),
            LLMError::ReqwestError(err) => write!(f, "Reqwest Error: {}", err),
            LLMError::IOError(err) => write!(f, "IO Error: {}", err),
            LLMError::Other(msg) => write!(f, "Other Error: {}", msg),
        }
    }
}

impl Error for LLMError {}

impl From<reqwest::Error> for LLMError {
    fn from(err: reqwest::Error) -> Self {
        LLMError::ReqwestError(err)
    }
}

impl From<serde_json::Error> for LLMError {
    fn from(err: serde_json::Error) -> Self {
        LLMError::SerializationError(err.to_string())
    }
}

impl From<io::Error> for LLMError {
    fn from(err: io::Error) -> Self {
        LLMError::IOError(err)
    }
}

#[derive(Debug)]
pub enum ImageGenError {
    APIError(String),
    DownloadError(String),
    ReqwestError(reqwest::Error),
    SerializationError(String),
    IOError(io::Error),
    Other(String),
}

impl fmt::Display for ImageGenError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            ImageGenError::APIError(msg) => write!(f, "API Error: {}", msg),
            ImageGenError::DownloadError(msg) => write!(f, "Download Error: {}", msg),
            ImageGenError::ReqwestError(err) => write!(f, "Reqwest Error: {}", err),
            ImageGenError::SerializationError(msg) => write!(f, "Serialization Error: {}", msg),
            ImageGenError::IOError(err) => write!(f, "IO Error: {}", err),
            ImageGenError::Other(msg) => write!(f, "Other Error: {}", msg),
        }
    }
}

impl Error for ImageGenError {}

impl From<reqwest::Error> for ImageGenError {
    fn from(err: reqwest::Error) -> Self {
        ImageGenError::ReqwestError(err)
    }
}

impl From<serde_json::Error> for ImageGenError {
    fn from(err: serde_json::Error) -> Self {
        ImageGenError::SerializationError(err.to_string())
    }
}

impl From<io::Error> for ImageGenError {
    fn from(err: io::Error) -> Self {
        ImageGenError::IOError(err)
    }
}

#[derive(Debug)]
pub enum StorageError {
    IOError(io::Error),
    SerializationError(String),
    SledError(sled::Error),
    BincodeError(BincodeError),
    Other(String),
}

impl fmt::Display for StorageError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            StorageError::IOError(err) => write!(f, "IO Error: {}", err),
            StorageError::SerializationError(msg) => write!(f, "Serialization Error: {}", msg),
            StorageError::SledError(err) => write!(f, "Sled Error: {}", err),
            StorageError::BincodeError(err) => write!(f, "Bincode Error: {}", err),
            StorageError::Other(msg) => write!(f, "Other Error: {}", msg),
        }
    }
}

impl Error for StorageError {}

impl From<io::Error> for StorageError {
    fn from(err: io::Error) -> Self {
        StorageError::IOError(err)
    }
}

impl From<serde_json::Error> for StorageError {
    fn from(err: serde_json::Error) -> Self {
        StorageError::SerializationError(err.to_string())
    }
}

impl From<sled::Error> for StorageError {
    fn from(err: sled::Error) -> Self {
        StorageError::SledError(err)
    }
}

impl From<BincodeError> for StorageError {
    fn from(err: BincodeError) -> Self {
        StorageError::BincodeError(err)
    }
}