1
use thiserror;
2

            
3
#[derive(thiserror::Error, Debug)]
4
pub enum Error {
5
    #[error(transparent)]
6
    Io(#[from] std::io::Error),
7

            
8
    #[error(transparent)]
9
    Nix(#[from] nix::Error),
10

            
11
    #[error(transparent)]
12
    RequestError(#[from] crate::tftp::RequestError),
13

            
14
    #[error("invalid pathname")]
15
    InvalidPathName,
16

            
17
    #[error("string conversion error")]
18
    StringConversion,
19

            
20
    #[error("failed to parse uri")]
21
    UriParse,
22

            
23
    #[error("file is missing")]
24
    FileMissing,
25

            
26
    #[error("internal error: {0}")]
27
    Internal(&'static str),
28

            
29
    #[error("timeout")]
30
    Timeout,
31

            
32
    #[error("bad ack package")]
33
    BadAck,
34

            
35
    #[error("generic protocol error: {0}")]
36
    Protocol(&'static str),
37

            
38
    #[error("operation not implemented")]
39
    NotImplemented,
40

            
41
    #[error("too much clients")]
42
    TooMuchClients,
43
}
44

            
45
impl Clone for Error {
46
    fn clone(&self) -> Self {
47
        match self {
48
            Self::Io(e) => Self::Io(e.kind().into()),
49
            Self::Nix(arg0) => Self::Nix(*arg0),
50
            Self::RequestError(arg0) => Self::RequestError(arg0.clone()),
51
            Self::InvalidPathName => Self::InvalidPathName,
52
            Self::StringConversion => Self::StringConversion,
53
            Self::UriParse => Self::UriParse,
54
            Self::FileMissing => Self::FileMissing,
55
            Self::Internal(arg0) => Self::Internal(arg0),
56
            Self::Timeout => Self::Timeout,
57
            Self::BadAck => Self::BadAck,
58
            Self::Protocol(arg0) => Self::Protocol(arg0),
59
            Self::NotImplemented => Self::NotImplemented,
60
            Self::TooMuchClients => Self::TooMuchClients,
61
        }
62
    }
63
}
64

            
65
pub type Result<T> = std::result::Result<T, Error>;