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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use crate::io_error::{AsyncIoError, ThreadedIoError};

#[derive(Debug, thiserror::Error)]
#[allow(clippy::large_enum_variant)]
pub enum BlockingDownloadError {
    #[error(transparent)]
    Io(#[from] ThreadedIoError),

    #[error("target directory does not exist {0}")]
    TargetDoesNotExist(String),

    #[error("request error: {0}")]
    Request(#[from] reqwest::Error),

    #[error("file name is too long (max 255 chars)")]
    FileNameTooLong,

    #[error("could not determine file name")]
    NoFileName,

    #[error(
        "Download file already exists: {0}. \
        If you want to over write this file then use overwrite_existing_file(true)"
    )]
    FileExists(String),

    #[error("http::Error:\n{0:#?}")]
    HttpError(#[from] http::Error),
}

impl From<std::io::Error> for BlockingDownloadError {
    fn from(err: std::io::Error) -> Self {
        Self::Io(ThreadedIoError::Std(err))
    }
}

#[derive(Debug, thiserror::Error)]
#[allow(clippy::large_enum_variant)]
pub enum AsyncDownloadError {
    #[error(transparent)]
    Io(#[from] AsyncIoError),

    #[error("target directory does not exist {0}")]
    TargetDoesNotExist(String),

    #[error("request error: {0}")]
    Request(#[from] reqwest::Error),

    #[error("file name is too long (max 255 chars)")]
    FileNameTooLong,

    #[error("could not determine file name")]
    NoFileName,

    #[error(
        "Download file already exists: {0}. \
        If you want to over write this file then use overwrite_existing_file(true)"
    )]
    FileExists(String),

    #[error("http::Error:\n{0:#?}")]
    HttpError(#[from] http::Error),
}

impl From<std::io::Error> for AsyncDownloadError {
    fn from(err: std::io::Error) -> Self {
        Self::Io(AsyncIoError::Std(err))
    }
}