Skip to content

Commit

Permalink
fix(config): use custom error type for UTF-8 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Aug 18, 2021
1 parent 183481b commit 45889c0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion git-cliff-core/src/embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl EmbeddedConfig {
/// Extracts the embedded content.
pub fn get_config() -> Result<String> {
match Self::get(crate::DEFAULT_CONFIG) {
Some(v) => Ok(str::from_utf8(&v.data.into_owned()).unwrap().to_string()),
Some(v) => Ok(str::from_utf8(&v.data.into_owned())?.to_string()),
None => Err(Error::EmbeddedError(String::from(
"Embedded config not found",
))),
Expand Down
4 changes: 4 additions & 0 deletions git-cliff-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ pub enum Error {
/// Error that may occur while I/O operations.
#[error("IO error: `{0}`")]
IoError(#[from] std::io::Error),
/// Error that may occur when attempting to interpret a sequence of u8 as a
/// string.
#[error("UTF-8 error: `{0}`")]
Utf8Error(#[from] std::str::Utf8Error),
/// Error variant that represents errors coming out of libgit2.
#[error("Git error: `{0}`")]
GitError(#[from] git2::Error),
Expand Down

0 comments on commit 45889c0

Please sign in to comment.