version_control_clean_check/
error.rs1use thiserror::Error;
2
3#[derive(Error, Debug)]
5#[non_exhaustive]
6pub enum VCSError {
7 #[error("no vcs")]
9 NoVCS,
10 #[error("{}", format_disallowed_files(dirty_files, staged_files))]
12 NotAllowedFilesFound {
13 dirty_files: Vec<String>,
15 staged_files: Vec<String>,
17 },
18 #[error(transparent)]
20 GitError(#[from] git2::Error),
21 #[error(transparent)]
23 Anyhow(#[from] anyhow::Error),
24}
25
26fn format_disallowed_files(dirty_files: &[String], staged_files: &[String]) -> String {
27 let mut files_list = String::new();
28 for file in dirty_files {
29 files_list.push_str(" * ");
30 files_list.push_str(file);
31 files_list.push_str(" (dirty)\n");
32 }
33 for file in staged_files {
34 files_list.push_str(" * ");
35 files_list.push_str(file);
36 files_list.push_str(" (staged)\n");
37 }
38
39 format!(
40 "disallowed files found:\n\
41 \n\
42 {}\n\
43 ",
44 files_list
45 )
46}