diff --git a/git-cliff-core/src/error.rs b/git-cliff-core/src/error.rs index c75a8120a5..fbee13a4a5 100644 --- a/git-cliff-core/src/error.rs +++ b/git-cliff-core/src/error.rs @@ -19,6 +19,9 @@ pub enum Error { /// Error that may occur while grouping commits. #[error("Grouping error: `{0}`")] GroupError(String), + /// Error that may occur while generating changelog. + #[error("Changelog error: `{0}`")] + ChangelogError(String), /// Error that may occur while template operations such as parse and render. #[error("Template error: `{0}`")] TemplateError(#[from] tera::Error), diff --git a/git-cliff/src/lib.rs b/git-cliff/src/lib.rs index b0b64c02d8..65c5d5fc59 100644 --- a/git-cliff/src/lib.rs +++ b/git-cliff/src/lib.rs @@ -86,7 +86,11 @@ pub fn run(mut args: Opt) -> Result<()> { commit_range = Some(format!("{}..HEAD", last_tag)); } } else if args.latest { - if let (Some(tag1), Some(tag2)) = ( + if tags.len() < 2 { + return Err(Error::ChangelogError(String::from( + "latest tag cannot be processed", + ))); + } else if let (Some(tag1), Some(tag2)) = ( tags.get_index(tags.len() - 2).map(|(k, _)| k), tags.get_index(tags.len() - 1).map(|(k, _)| k), ) {