From 60985236c7070425c28aa0c5ce675306d06ab123 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Thu, 16 Jan 2025 14:45:14 -0500 Subject: initial --- src/error.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/error.rs (limited to 'src/error.rs') diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..65e7aff --- /dev/null +++ b/src/error.rs @@ -0,0 +1,49 @@ +//! 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; -- cgit v1.2.3-freya