Skip to content

Commit

Permalink
Add error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
c-git committed Nov 4, 2023
1 parent d73d0a6 commit ac0c09a
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::{error::Error, fmt::Display};

/// Enumerates the possible error values that can be generated by this crate
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
#[non_exhaustive]
Expand All @@ -12,3 +14,38 @@ pub enum VSCError {
staged_files: Vec<String>,
},
}

impl Display for VSCError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
VSCError::NoVCS => write!(f, "no VCS found but this not allowed"),
VSCError::NotAllowedFilesFound {
dirty_files,
staged_files,
} => {
let mut files_list = String::new();
for file in dirty_files {
files_list.push_str(" * ");
files_list.push_str(file);
files_list.push_str(" (dirty)\n");
}
for file in staged_files {
files_list.push_str(" * ");
files_list.push_str(file);
files_list.push_str(" (staged)\n");
}

write!(
f,
"disallowed files found:\n\
\n\
{}\n\
",
files_list
)
}
}
}
}

impl Error for VSCError {}

0 comments on commit ac0c09a

Please sign in to comment.