1use git2::{ErrorClass, ErrorCode};
21use semver::{Version, VersionReq};
22
23#[derive(Debug)]
24pub enum Error {
25 ConfigurationNotFound,
26 ConfigurationParseError(toml::de::Error),
27 ConfigurationEncodingError(std::str::Utf8Error),
28 UnableToDetermineYactPath,
29 PreCommitHookAlreadyExists,
30 InvalidYactVersion(VersionReq, Version),
31 InvalidGlob(String),
32 RepositoryNotFound,
33 RepositoryIsBare,
34
35 GitError(git2::Error),
37
38 TransformerError(String),
40
41 IoError(std::io::Error),
43
44 EmptyIndex,
48}
49
50impl From<toml::de::Error> for Error {
51 fn from(err: toml::de::Error) -> Self {
52 Self::ConfigurationParseError(err)
53 }
54}
55
56impl From<git2::Error> for Error {
57 fn from(err: git2::Error) -> Self {
58 if matches!(err.class(), ErrorClass::Repository)
59 && matches!(err.code(), ErrorCode::NotFound)
60 {
61 Self::RepositoryNotFound
62 } else {
63 Self::GitError(err)
64 }
65 }
66}
67
68impl From<std::io::Error> for Error {
69 fn from(value: std::io::Error) -> Self {
70 Self::IoError(value)
71 }
72}
73
74impl From<String> for Error {
75 fn from(err: String) -> Self {
76 Self::TransformerError(err)
77 }
78}
79
80impl From<std::str::Utf8Error> for Error {
81 fn from(err: std::str::Utf8Error) -> Self {
82 Self::ConfigurationEncodingError(err)
83 }
84}