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
use crate::{AsRes, GraphFailure, GraphResult};

#[derive(Debug, Snafu)]
pub enum GraphRsError {
    #[snafu(display("Download directory does not exist: {}", dir))]
    DownloadDirNoExists { dir: String },
    #[snafu(display(
        "Download file already exists: {}. \
         If you want to over write this file then use overwrite_existing_file(true)",
        name
    ))]
    DownloadFileExists { name: String },
    #[snafu(display("Could not determine file name or the file name exceeded 255 characters"))]
    DownloadFileName,
    #[snafu(display("File name has invalid characters. Must be UTF-8"))]
    FileNameInvalidUTF8,
    #[snafu(display("Missing or invalid: Error: {}", msg))]
    InvalidOrMissing { msg: String },
    #[snafu(display("Invalid file extension. Requires {} but found {}", requires, found))]
    InvalidFileExtension { requires: String, found: String },
}

impl AsRes for GraphRsError {
    fn as_err_res<T>(self) -> GraphResult<T> {
        GraphFailure::internal(self).as_err_res()
    }

    fn as_failure(self) -> GraphFailure {
        GraphFailure::internal(self)
    }
}