1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use thiserror::Error as ThisError;
#[derive(Debug, ThisError)]
pub enum Error {
#[error("IO error: `{0}`")]
IoError(#[from] std::io::Error),
#[error("UTF-8 error: `{0}`")]
Utf8Error(#[from] std::str::Utf8Error),
#[error("Git error: `{0}`")]
GitError(#[from] git2::Error),
#[error("Cannot parse config: `{0}`")]
ConfigError(#[from] config::ConfigError),
#[error("Cannot parse the commit: `{0}`")]
ParseError(#[from] git_conventional::Error),
#[error("Grouping error: `{0}`")]
GroupError(String),
#[error("Changelog error: `{0}`")]
ChangelogError(String),
#[error("Template parse error:\n{0}")]
TemplateParseError(String),
#[error("Template render error:\n{0}")]
TemplateRenderError(String),
#[error("Template error: `{0}`")]
TemplateError(#[from] tera::Error),
#[error("Argument error: `{0}`")]
ArgumentError(String),
#[error("Embedded error: `{0}`")]
EmbeddedError(String),
#[error("Cannot parse TOML: `{0}`")]
DeserializeError(#[from] toml::de::Error),
#[error("Cannot de/serialize JSON: `{0}`")]
JsonError(#[from] serde_json::Error),
#[error("Cannot parse/compile regex: `{0}`")]
RegexError(#[from] regex::Error),
#[error("System time error: `{0}`")]
SystemTimeError(#[from] std::time::SystemTimeError),
#[error("Failed to parse integer: `{0}`")]
IntParseError(#[from] std::num::TryFromIntError),
}
pub type Result<T> = core::result::Result<T, Error>;
#[cfg(test)]
mod test {
use super::*;
use git_conventional::{
Commit,
ErrorKind,
};
fn mock_function() -> super::Result<Commit<'static>> {
Ok(Commit::parse("test")?)
}
#[test]
fn throw_parse_error() {
let actual_error = mock_function().expect_err("expected error");
let expected_error_kind = ErrorKind::MissingType;
match actual_error {
Error::ParseError(e) => {
assert_eq!(expected_error_kind, e.kind());
}
_ => {
unreachable!()
}
}
}
}