#[derive(Clone, Debug)]
pub struct Error(String, Option<String>);
impl Error {
pub fn new(message: &str, details: Option<&str>) -> Self {
Error(message.to_string(), details.map(|d| d.to_string()))
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
f,
"{}\n\n{}",
self.0,
console::style(self.1.clone().unwrap_or("".into())).dim()
)
}
}
impl std::error::Error for Error {}
impl From<eyre::ErrReport> for Error {
fn from(error: eyre::ErrReport) -> Self {
error
.downcast::<Error>()
.unwrap_or_else(|err| Error::new(&err.to_string(), None))
}
}