mirror of
https://github.com/orhun/git-cliff.git
synced 2024-12-01 21:05:17 +03:00
feat(error): add custom error
Signed-off-by: Taylan Dogan <git@taylandogan.info>
This commit is contained in:
parent
a9402ca7b6
commit
1e9c107f38
23
Cargo.lock
generated
23
Cargo.lock
generated
@ -84,6 +84,9 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "gitolith-core"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
@ -284,6 +287,26 @@ dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0f4a65597094d4483ddaed134f409b2cb7c1beccf25201a9f73c719254fa98e"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.7.1"
|
||||
|
@ -13,3 +13,4 @@ categories = []
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
thiserror = "1.0"
|
||||
|
29
gitolith-core/src/error.rs
Normal file
29
gitolith-core/src/error.rs
Normal file
@ -0,0 +1,29 @@
|
||||
use thiserror::Error as ThisError;
|
||||
|
||||
/// Githolit-core related errors that we are exposing to the rest of the
|
||||
/// workspaces.
|
||||
#[derive(Debug, ThisError, PartialEq)]
|
||||
pub enum Error {
|
||||
/// When commit's not follow the conventional commit structure we throw this
|
||||
/// error.
|
||||
#[error("Cannot parse the commit")]
|
||||
ParseError,
|
||||
}
|
||||
|
||||
/// Result type of the githolit-core libraries.
|
||||
pub type Result<T> = core::result::Result<T, Error>;
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
fn mock_function() -> super::Result<()> {
|
||||
return Err(Error::ParseError);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn throw_parse_error() {
|
||||
let actual_error = mock_function().unwrap_err();
|
||||
let expected_error = Error::ParseError;
|
||||
assert_eq!(actual_error, expected_error);
|
||||
}
|
||||
}
|
@ -1,7 +1 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn it_works() {
|
||||
assert_eq!(2 + 2, 4);
|
||||
}
|
||||
}
|
||||
pub mod error;
|
||||
|
Loading…
Reference in New Issue
Block a user