summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Grunert <mail@saschagrunert.de>2016-11-16 14:49:23 +0100
committerSascha Grunert <mail@saschagrunert.de>2016-11-16 14:49:23 +0100
commitc98f028d01af86abf2738984f6eda03006c9c649 (patch)
treefb0cc6f10b3733ec0bea4f489a838a072c8ca72b
parent0adc9580f67cfac66b5b1a66b643cb8fefa66a99 (diff)
Fixed parsing bug with empty commit message parts
-rw-r--r--src/errors.rs34
-rw-r--r--src/parser.rs21
2 files changed, 15 insertions, 40 deletions
diff --git a/src/errors.rs b/src/errors.rs
index 3074656..64fd7e3 100644
--- a/src/errors.rs
+++ b/src/errors.rs
@@ -12,34 +12,7 @@ use toml;
pub type GitJournalResult<T> = Result<T, Box<GitJournalError>>;
/// GitJournal error trait
-pub trait GitJournalError: Error + Send + 'static {
- /// The internal cause for the error
- fn gitjournal_cause(&self) -> Option<&GitJournalError> {
- None
- }
-
- /// Convert the `GitJournalError` to an `Error`
- fn as_error(&self) -> &Error
- where Self: Sized
- {
- self as &Error
- }
-}
-
-impl Error for Box<GitJournalError> {
- fn description(&self) -> &str {
- (**self).description()
- }
- fn cause(&self) -> Option<&Error> {
- (**self).cause()
- }
-}
-
-impl GitJournalError for Box<GitJournalError> {
- fn gitjournal_cause(&self) -> Option<&GitJournalError> {
- (**self).gitjournal_cause()
- }
-}
+pub trait GitJournalError: Error + Send + 'static {}
/// Concrete errors
struct ConcreteGitJournalError {
@@ -52,7 +25,7 @@ impl fmt::Display for ConcreteGitJournalError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description)?;
if let Some(ref s) = self.detail {
- write!(f, " ({})", s)?;
+ write!(f, ": {}", s)?;
}
Ok(())
}
@@ -76,8 +49,6 @@ impl Error for ConcreteGitJournalError {
}
}
-impl GitJournalError for ConcreteGitJournalError {}
-
/// Various error implementors
macro_rules! from_error {
($($p:ty,)*) => (
@@ -102,6 +73,7 @@ impl GitJournalError for log::ShutdownLoggerError {}
impl GitJournalError for num::ParseIntError {}
impl GitJournalError for term::Error {}
impl GitJournalError for toml::Error {}
+impl GitJournalError for ConcreteGitJournalError {}
/// Raise and internal error
pub fn internal_error(error: &str, detail: &str) -> Box<GitJournalError> {
diff --git a/src/parser.rs b/src/parser.rs
index bc79d30..1b9addf 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -825,14 +825,16 @@ impl Parser {
// Parse the body and the footer, the summary is already consumed
let mut parsed_footer = vec![];
let mut parsed_body = vec![];
+
+ // Iterate over all the commit message parts
for part in commit_parts {
- // Do nothing on comments
- if RE_COMMENT.is_match(part) {
+ // Do nothing on comments and empty parts
+ if RE_COMMENT.is_match(part) || part.is_empty() {
continue;
+ // Parse the footer
} else if RE_FOOTER.is_match(part) {
- // Parse footer
for cap in RE_FOOTER.captures_iter(part) {
parsed_footer.push(FooterElement {
oid: oid,
@@ -841,8 +843,8 @@ impl Parser {
});
}
+ // Parse all list items
} else if RE_LIST.is_match(part) {
- // Parse list items
let mut list = vec![];
for list_item in part.lines() {
if let (_, IResult::Done(_, mut result)) = self.clone().parse_list_item(list_item.as_bytes()) {
@@ -852,17 +854,18 @@ impl Parser {
}
parsed_body.push(BodyElement::List(list));
- } else {
- // Assume paragraph, test for a valid paragraph
- if !RE_PARAGRAPH.is_match(part) {
- bail!("Paragraph parsing error: '{}'", part)
- }
+ // Nothing of tbe above items matched, check for a Paragraph element
+ } else if RE_PARAGRAPH.is_match(part) {
let (parsed_tags, parsed_text) = Self::parse_and_consume_tags(part.as_bytes());
parsed_body.push(BodyElement::Paragraph(ParagraphElement {
oid: oid,
text: parsed_text.trim().to_owned(),
tags: parsed_tags,
}));
+
+ // Nothing matched, this should not happen at all
+ } else {
+ bail!("Could not parse commit message part: '{}'", part);
}
}