Skip to main content

asanadw/
error.rs

1use std::fmt;
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5pub enum Error {
6    #[error("Asana API error: {0}")]
7    Api(#[from] asanaclient::Error),
8
9    #[error("Database error: {0}")]
10    Database(String),
11
12    #[error("Migration error: {0}")]
13    Migration(String),
14
15    #[error("Sync error for {entity_key}: {message}")]
16    Sync { entity_key: String, message: String },
17
18    #[error("Invalid URL: {0}")]
19    UrlParse(String),
20
21    #[error("Invalid identifier: {0}")]
22    InvalidIdentifier(String),
23
24    #[error("Invalid period format: {0}")]
25    PeriodParse(String),
26
27    #[error("Configuration error: {0}")]
28    Config(String),
29
30    #[error("LLM error: {0}")]
31    Llm(String),
32
33    #[error("Entity not found: {0}")]
34    NotFound(String),
35
36    #[error("{0}")]
37    Other(String),
38}
39
40impl From<rusqlite::Error> for Error {
41    fn from(e: rusqlite::Error) -> Self {
42        Error::Database(e.to_string())
43    }
44}
45
46impl From<rusqlite_migration::Error> for Error {
47    fn from(e: rusqlite_migration::Error) -> Self {
48        Error::Migration(e.to_string())
49    }
50}
51
52impl<E: fmt::Display> From<tokio_rusqlite::Error<E>> for Error {
53    fn from(e: tokio_rusqlite::Error<E>) -> Self {
54        Error::Database(e.to_string())
55    }
56}
57
58pub type Result<T> = std::result::Result<T, Error>;