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) + } +}