system-updater/src/errors.rs

48 lines
1.1 KiB
Rust
Raw Normal View History

2023-07-05 21:09:56 +02:00
// Use https://kazlauskas.me/entries/errors as a reference
2023-01-28 19:20:37 +01:00
use crate::*;
use std::io;
2023-01-28 22:24:39 +01:00
use std::result;
2023-07-05 21:09:56 +02:00
use thiserror::Error;
2023-01-28 22:24:39 +01:00
2023-07-05 21:09:56 +02:00
pub type Result<T> = result::Result<T, Error>;
2023-01-07 17:08:44 +01:00
/// Result wrapper used to easily `Display` the Status of an execution
pub struct Status {
result: Result<()>,
}
impl Display for Status {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Status { result: Ok(_) } => write!(f, "Ok"),
Status { result: Err(e) } => write!(f, "Error: {}", e),
}
}
}
impl From<Result<()>> for Status {
fn from(result: Result<()>) -> Self {
Status { result }
}
}
2023-01-07 17:08:44 +01:00
/// An error that can occur in this crate.
///
/// Generally, this error corresponds to problems with underlying process.
#[non_exhaustive]
2023-07-05 21:09:56 +02:00
#[derive(Debug, Error)]
pub enum Error {
// #[error("TODO")]
// Config,
#[error(
"Could not achieve the \"{step}\" step. Command `{cmd}` resulted in an exited with: {source}"
)]
Execution {
source: io::Error,
step: UpdateSteps,
cmd: ActualCmd,
},
2023-01-07 17:08:44 +01:00
}