system-updater/src/errors.rs
2023-07-12 00:46:13 +02:00

46 lines
1.1 KiB
Rust
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Use https://kazlauskas.me/entries/errors as a reference
use crate::*;
use std::io;
use std::result;
use thiserror::Error;
pub type Result<T> = result::Result<T, Error>;
/// 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 }
}
}
/// An error that can occur in this crate.
///
/// Generally, this error corresponds to problems with underlying process.
#[non_exhaustive]
#[derive(Debug, Error)]
pub enum Error {
// #[error("TODO")]
// Config,
#[error("Could not achieve the \"{step}\" step. Command `{cmd}` exited with: {source}")]
Execution {
source: io::Error,
step: UpdateSteps,
cmd: ActualCmd,
},
}