//! Definition of an iris [error][Error]. use std::fmt; use std::io; macro_rules! error { ($($arg:tt)*) => { $crate::error::Error::new(format!($($arg)*)) }; } pub(crate) use error; /// Errors that can occur in iris #[derive(thiserror::Error, Debug)] pub enum Error { /// Occurs when a file could not be read, or could not be written to. #[error(transparent)] Io(#[from] io::Error), /// Occurs when an error was raised from the local git repository #[error(transparent)] Git(#[from] git2::Error), /// Occurs when iris failed to convert its internal structures into the /// config string representation. #[error(transparent)] De(#[from] crate::parse::de::Error), /// Occurs when a provided string representation of an iris structure is /// invalid and could not be converted/parsed. #[error(transparent)] Ser(#[from] crate::parse::ser::Error), /// Generic error message, occurs anywhere #[error("{0}")] Custom(String), } impl Error { pub fn new(fmt: impl fmt::Display) -> Self { Self::Custom(fmt.to_string()) } } impl From<&str> for Error { fn from(msg: &str) -> Self { Self::new(msg) } } /// iris result type pub type Result = std::result::Result;