1pub type Result<T> = std::result::Result<T, TloxError>;
2
3#[derive(Debug)]
4pub enum TloxError {
5 Database(rusqlite::Error),
6 InvalidTarget(String),
7 Io(std::io::Error),
8 InvalidTimestamp(std::time::SystemTimeError),
9 MissingApiKey,
10 AnthropicApi(String),
11 Auth(String),
13 Network(String),
15}
16
17impl std::fmt::Display for TloxError {
18 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19 match self {
20 Self::Database(error) => write!(f, "database error: {error}"),
21 Self::InvalidTarget(target) => write!(f, "invalid target: {target}"),
22 Self::Io(error) => write!(f, "i/o error: {error}"),
23 Self::InvalidTimestamp(error) => write!(f, "timestamp error: {error}"),
24 Self::MissingApiKey => write!(f, "ANTHROPIC_API_KEY is not set"),
25 Self::AnthropicApi(message) => write!(f, "{message}"),
26 Self::Auth(message) => write!(f, "{message}"),
27 Self::Network(message) => write!(f, "{message}"),
28 }
29 }
30}
31
32impl std::error::Error for TloxError {}
33
34impl From<rusqlite::Error> for TloxError {
35 fn from(error: rusqlite::Error) -> Self {
36 Self::Database(error)
37 }
38}
39
40impl From<std::io::Error> for TloxError {
41 fn from(error: std::io::Error) -> Self {
42 Self::Io(error)
43 }
44}
45
46impl From<std::time::SystemTimeError> for TloxError {
47 fn from(error: std::time::SystemTimeError) -> Self {
48 Self::InvalidTimestamp(error)
49 }
50}