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
use thiserror::Error;

#[derive(Debug, Error)]
pub enum OneIoError {
    #[cfg(feature = "remote")]
    #[error("remote IO error: {0}")]
    RemoteIoError(#[from] reqwest::Error),
    #[cfg(feature = "remote")]
    #[error("FTP error: {0}")]
    FptError(#[from] suppaftp::FtpError),
    #[cfg(feature = "json")]
    #[error("JSON object parsing error: {0}")]
    JsonParsingError(#[from] serde_json::Error),
    #[error("End-of-file error: {0}")]
    EofError(std::io::Error),
    #[error("IO error: {0}")]
    IoError(std::io::Error),
    #[error("Not supported error: {0}")]
    NotSupported(String),
    #[error("Cache IO error: {0}")]
    CacheIoError(String),

    #[cfg(feature = "s3")]
    #[error("S3 IO error: {0}")]
    S3IoError(#[from] s3::error::S3Error),
    #[cfg(feature = "s3")]
    #[error("S3 credential error: {0}")]
    S3CredentialError(#[from] s3::creds::error::CredentialsError),
    #[cfg(feature = "s3")]
    #[error("S3 invalid url: {0}")]
    S3UrlError(String),
    #[cfg(feature = "s3")]
    #[error("S3 region error: {0}")]
    S3RegionError(#[from] s3::region::error::RegionError),
    #[cfg(feature = "s3")]
    #[error("S3 download error: code {0}")]
    S3DownloadError(u16),
}

impl From<std::io::Error> for OneIoError {
    fn from(io_error: std::io::Error) -> Self {
        match io_error.kind() {
            std::io::ErrorKind::UnexpectedEof => OneIoError::EofError(io_error),
            _ => OneIoError::IoError(io_error),
        }
    }
}