cooklang_sync_client/
errors.rs

1use std::path::PathBuf;
2use thiserror::Error;
3
4#[derive(Error, Debug, uniffi::Error)]
5#[uniffi(flat_error)]
6pub enum SyncError {
7    #[error("IO error in file {path}: {source}")]
8    IoError {
9        path: String,
10        source: std::io::Error,
11    },
12    #[error("IO error {0}")]
13    IoErrorGeneric(#[from] std::io::Error),
14    #[error("Notify error {0}")]
15    NotifyError(#[from] notify::Error),
16    #[error("Strip prefix error {0}")]
17    StripPrefix(#[from] std::path::StripPrefixError),
18    #[error("System time error {0}")]
19    SystemTime(#[from] std::time::SystemTimeError),
20    #[error("Conversion error {0}")]
21    Convert(#[from] std::num::TryFromIntError),
22    #[error("Database query error {0}")]
23    DBQueryError(#[from] diesel::result::Error),
24    #[error("Reqwest error {0}")]
25    ReqwestError(#[from] reqwest::Error),
26    #[error("Reqwest with middleware error {0}")]
27    ReqwestWirhMiddlewareError(#[from] reqwest_middleware::Error),
28    #[error("Error sending value to a channel {0}")]
29    ChannelSendError(#[from] futures::channel::mpsc::SendError),
30    #[error("Connection init error {0}")]
31    ConnectionInitError(String),
32    #[error("Unauthorized token")]
33    Unauthorized,
34    #[error("Can't parse the response")]
35    BodyExtractError,
36    #[error("Can't find in cache")]
37    GetFromCacheError,
38    #[error("Unlisted file format {0}")]
39    UnlistedFileFormat(String),
40    #[error("Unknown error")]
41    Unknown,
42    #[error("Batch download error {0}")]
43    BatchDownloadError(String),
44}
45
46impl SyncError {
47    pub fn from_io_error(path: impl Into<PathBuf>, error: std::io::Error) -> Self {
48        SyncError::IoError {
49            path: path.into().display().to_string(),
50            source: error,
51        }
52    }
53}