r_tftpd_proxy/
errors.rs

1use thiserror;
2
3#[derive(thiserror::Error, Debug)]
4pub 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    HttpError(#[from] reqwest::Error),
13
14    // helper because reqwest::Error does not implement Clone
15    #[error("http error: {0}")]
16    HttpErrorStr(Box<str>),
17
18    #[error("request failed with status {0}")]
19    HttpStatus(reqwest::StatusCode),
20
21    #[error("bad http time")]
22    BadHttpTime,
23
24    #[error("string conversion error")]
25    StringConversion,
26
27    #[error("internal error: {0}")]
28    Internal(&'static str),
29}
30
31pub type Result<T> = std::result::Result<T, Error>;
32
33impl Clone for Error {
34    fn clone(&self) -> Self {
35        match self {
36            Self::Io(e) => Self::Io(e.kind().into()),
37            Self::Nix(arg0) => Self::Nix(*arg0),
38            Self::HttpError(arg0) => Self::HttpErrorStr(format!("{arg0}").into()),
39            Self::HttpErrorStr(arg0) => Self::HttpErrorStr(arg0.clone()),
40	    Self::HttpStatus(s) => Self::HttpStatus(*s),
41            Self::BadHttpTime => Self::BadHttpTime,
42            Self::StringConversion => Self::StringConversion,
43            Self::Internal(arg0) => Self::Internal(arg0),
44	}
45    }
46}