mod tools;
use std::fmt;
use std::io;
#[derive(Debug)]
pub struct Error {
inner: Box<ErrorKind>,
}
#[derive(Debug, thiserror::Error)]
enum ErrorKind {
#[error(transparent)]
Tools(#[from] tools::ToolError),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.inner)
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
self.inner.source()
}
}
impl Error {
pub fn tool_io(err: io::Error) -> Self {
Error {
inner: Box::new(ErrorKind::Tools(tools::ToolError::Io(err))),
}
}
pub fn tool_cmd_failed(code: i32) -> Self {
Error {
inner: Box::new(ErrorKind::Tools(tools::ToolError::CommandFailed(code))),
}
}
pub fn tool_timeout() -> Self {
Error {
inner: Box::new(ErrorKind::Tools(tools::ToolError::Timeout)),
}
}
}
pub type Result<T> = std::result::Result<T, Error>;