use std::error::Error;
use std::fmt::Write;
#[derive(serde::Serialize, serde::Deserialize, Clone)]
pub struct UnigraphError {
pub display: String,
pub debug: Option<String>,
}
impl Error for UnigraphError {}
impl UnigraphError {
pub fn new<DS: Into<String>, DB: Into<String>>(display: DS, debug: Option<DB>) -> Self {
UnigraphError {
display: display.into(),
debug: debug.map(|d| d.into()),
}
}
pub fn append_debug_info(&mut self, s: &str) {
let mut result = String::new();
if let Some(existing) = self.debug.take() {
writeln!(result, "{existing}").unwrap();
writeln!(result, "{}", crate::SEPARATOR).unwrap();
}
writeln!(result, "{s}").unwrap();
self.debug = Some(result);
}
}
impl From<anyhow::Error> for UnigraphError {
fn from(error: anyhow::Error) -> Self {
super::into_unigraph_error(&error)
}
}