use std::{
error as std_error,
fmt as std_fmt,
io as std_io,
};
#[derive(Debug)]
pub enum VersionError {
InvocationFailed(std_io::Error),
InvalidUtf8,
UnrecognisedOutput,
InvalidVersionComponent {
component : &'static str,
value : String,
},
}
impl std_fmt::Display for VersionError {
fn fmt(
&self,
f : &mut std_fmt::Formatter<'_>,
) -> std_fmt::Result {
match self {
Self::InvocationFailed(e) => {
write!(f, "failed to execute tool `--version`: {e}")
},
Self::InvalidUtf8 => {
write!(f, "tool `--version` stdout was not valid UTF-8")
},
Self::UnrecognisedOutput => {
write!(f, "tool `--version` output was not recognised")
},
Self::InvalidVersionComponent { component, value } => {
write!(
f,
"invalid {component} component in tool `--version` output: {value:?}"
)
},
}
}
}
impl std_error::Error for VersionError {
fn source(&self) -> Option<&(dyn std_error::Error + 'static)> {
match self {
Self::InvocationFailed(e) => Some(e),
_ => None,
}
}
}