From 4139733c5cd0003f0fc2f956dff87e3ce74b0425 Mon Sep 17 00:00:00 2001 From: Adam French Date: Mon, 2 Mar 2026 21:55:15 +0000 Subject: [PATCH] adding new errors --- src/error.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/error.rs diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..a74d313 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,31 @@ +use std::io; +use std::path::PathBuf; + +#[derive(Debug)] +pub enum CommitError { + NotADescendantOfCurrentDir(PathBuf), + InsideTourDir(PathBuf), + Io(io::Error), +} + +impl std::fmt::Display for CommitError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::NotADescendantOfCurrentDir(path) => { + write!(f, "File {:?} is not a descendant of the working directory.", path) + } + Self::InsideTourDir(path) => { + write!(f, "File {:?} is inside a .tour directory, which is not allowed.", path) + } + Self::Io(e) => write!(f, "IO error: {}", e), + } + } +} + +impl std::error::Error for CommitError {} + +impl From for CommitError { + fn from(e: io::Error) -> Self { + Self::Io(e) + } +}