summaryrefslogtreecommitdiffstats
path: root/plugins/tedge_apt_plugin/src/error.rs
blob: c9332cf3563f5c1035aba1e9e5fbdcd415b5b0ad (plain)
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
#[derive(thiserror::Error, Debug)]
pub enum InternalError {
    #[error("Fail to run `{cmd}`: {from}")]
    ExecError { cmd: String, from: std::io::Error },

    #[error(transparent)]
    FromIo(#[from] std::io::Error),

    #[error(transparent)]
    FromUtf8(#[from] std::string::FromUtf8Error),

    #[error(transparent)]
    FromCsv(#[from] csv::Error),

    #[error("Parsing Debian package failed for `{file}`, Error: {error}")]
    ParsingError { file: String, error: String },

    #[error("Validation of {package} metadata failed, expected value for the {expected_key} is {expected_value}, but provided {provided_value}")]
    MetaDataMismatch {
        package: String,
        expected_key: String,
        expected_value: String,
        provided_value: String,
    },
}

impl InternalError {
    pub fn exec_error(cmd: impl Into<String>, from: std::io::Error) -> InternalError {
        InternalError::ExecError {
            cmd: cmd.into(),
            from,
        }
    }
}