summaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-01-16 14:45:14 -0500
committerFreya Murphy <freya@freyacat.org>2025-01-16 14:45:14 -0500
commit60985236c7070425c28aa0c5ce675306d06ab123 (patch)
tree7448aef5dadf19d4504151ebc370f9e20757ef10 /src/error.rs
downloadiris-60985236c7070425c28aa0c5ce675306d06ab123.tar.gz
iris-60985236c7070425c28aa0c5ce675306d06ab123.tar.bz2
iris-60985236c7070425c28aa0c5ce675306d06ab123.zip
initialHEADmain
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs49
1 files changed, 49 insertions, 0 deletions
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<T> = std::result::Result<T, Error>;