1
1
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:
Taylan Dogan 2021-05-14 23:29:33 +03:00
parent a9402ca7b6
commit 1e9c107f38
No known key found for this signature in database
GPG Key ID: 6D2E6AFE58ADCA37
4 changed files with 54 additions and 7 deletions

23
Cargo.lock generated
View File

@ -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"

View File

@ -13,3 +13,4 @@ categories = []
edition = "2018"
[dependencies]
thiserror = "1.0"

View 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);
}
}

View File

@ -1,7 +1 @@
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
pub mod error;