system_updater/
errors.rs

1// Use https://kazlauskas.me/entries/errors as a reference
2
3use crate::*;
4
5use std::io;
6use std::result;
7use thiserror::Error;
8
9pub type Result<T> = result::Result<T, Error>;
10
11/// Result wrapper used to easily `Display` the Status of an execution
12pub struct Status {
13    result: Result<()>,
14}
15
16impl Display for Status {
17    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18        match self {
19            Status { result: Ok(_) } => write!(f, "Ok"),
20            Status { result: Err(e) } => write!(f, "Error: {}", e),
21        }
22    }
23}
24
25impl From<Result<()>> for Status {
26    fn from(result: Result<()>) -> Self {
27        Status { result }
28    }
29}
30
31/// An error that can occur in this crate.
32///
33/// Generally, this error corresponds to problems with underlying process.
34#[non_exhaustive]
35#[derive(Debug, Error)]
36pub enum Error {
37    // TODO: This error is meh, better get the full list of errors for a Packager and then if all executors are in error have a generic one? Or details all and ask to fix one?
38    #[error(
39        r#"No configured executor could be run, last one returned: {source} for "{filename}""#
40    )]
41    Config {
42        source: which::Error,
43        filename: String,
44    },
45    #[error("Could not achieve the \"{step}\" step. Command `{cmd}` exited with: {source}")]
46    Execution {
47        source: io::Error,
48        step: UpdateSteps,
49        cmd: ActualCmd,
50    },
51}