46 lines
1.1 KiB
Rust
46 lines
1.1 KiB
Rust
// 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,
|
||
},
|
||
}
|