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