1use thiserror::Error as ThisError;
2
3#[derive(Debug, ThisError)]
5pub enum Error {
6 #[error("IO error: `{0}`")]
8 IoError(#[from] std::io::Error),
9 #[error("UTF-8 error: `{0}`")]
12 Utf8Error(#[from] std::str::Utf8Error),
13 #[cfg(feature = "repo")]
15 #[error("Git error: `{0}`")]
16 GitError(#[from] git2::Error),
17 #[cfg(feature = "repo")]
19 #[error(
20 "Failed to set the commit range: {1}
21{0:?} is not a valid commit range. Did you provide the correct arguments?"
22 )]
23 SetCommitRangeError(String, #[source] git2::Error),
24 #[cfg(feature = "repo")]
26 #[error("Git repository error: `{0}`")]
27 RepoError(String),
28 #[error("Cannot parse config: `{0}`")]
30 ConfigError(#[from] config::ConfigError),
31 #[error("Logger error: `{0}`")]
33 LoggerError(String),
34 #[error("Cannot parse the commit: `{0}`")]
37 ParseError(#[from] git_conventional::Error),
38 #[error("Grouping error: `{0}`")]
40 GroupError(String),
41 #[error("Changelog error: `{0}`")]
43 ChangelogError(String),
44 #[error("Template parse error:\n{0}")]
46 TemplateParseError(String),
47 #[error("Template render error:\n{0}")]
49 TemplateRenderError(String),
50 #[error("Template render error:\n{0}\n{1}")]
52 TemplateRenderDetailedError(String, String),
53 #[error("Template error: `{0}`")]
55 TemplateError(#[from] tera::Error),
56 #[error("Argument error: `{0}`")]
58 ArgumentError(String),
59 #[error("Embedded error: `{0}`")]
61 EmbeddedError(String),
62 #[error("Cannot parse TOML: `{0}`")]
64 DeserializeError(#[from] toml::de::Error),
65 #[error("Cannot de/serialize JSON: `{0}`")]
67 JsonError(#[from] serde_json::Error),
68 #[error("Cannot parse/compile regex: `{0}`")]
70 RegexError(#[from] regex::Error),
71 #[error("System time error: `{0}`")]
73 SystemTimeError(#[from] std::time::SystemTimeError),
74 #[error("Failed to parse integer: `{0}`")]
76 IntParseError(#[from] std::num::TryFromIntError),
77 #[error("Field error: `{0}`")]
80 FieldError(String),
81 #[error("Semver error: `{0}`")]
84 SemverError(#[from] semver::Error),
85 #[error("HTTP client error: `{0}`")]
87 #[cfg(feature = "remote")]
88 HttpClientError(#[from] reqwest::Error),
89 #[error("HTTP client with middleware error: `{0}`")]
92 #[cfg(feature = "remote")]
93 HttpClientMiddlewareError(#[from] reqwest_middleware::Error),
94 #[error("HTTP header error: `{0}`")]
97 #[cfg(feature = "remote")]
98 HttpHeaderError(#[from] reqwest::header::InvalidHeaderValue),
99 #[error("Pagination error: `{0}`")]
101 PaginationError(String),
102 #[error("URL parse error: `{0}`")]
104 UrlParseError(#[from] url::ParseError),
105 #[error("Repository remote is not set.")]
107 RemoteNotSetError,
108 #[error("Directory error: `{0}`")]
110 DirsError(String),
111 #[error("Pattern error: `{0}`")]
113 PatternError(#[from] glob::PatternError),
114 #[error(
117 "Requiring all commits be conventional but found {0} unconventional \
118 commits."
119 )]
120 UnconventionalCommitsError(i32),
121}
122
123pub type Result<T> = core::result::Result<T, Error>;
125
126#[cfg(test)]
127mod test {
128 use super::*;
129 use git_conventional::{
130 Commit,
131 ErrorKind,
132 };
133 fn mock_function() -> super::Result<Commit<'static>> {
134 Ok(Commit::parse("test")?)
135 }
136
137 #[test]
138 fn throw_parse_error() {
139 let actual_error = mock_function().expect_err("expected error");
140 let expected_error_kind = ErrorKind::MissingType;
141 match actual_error {
142 Error::ParseError(e) => {
143 assert_eq!(expected_error_kind, e.kind());
144 }
145 _ => {
146 unreachable!()
147 }
148 }
149 }
150}