Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(issue-4): make error reporting more user friendly #11

Merged
merged 2 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions src/bumping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::str::FromStr;
use git2::Commit;
use semver::Version;
use simple_error::SimpleError;
use log::debug;

/// Extension methods for `&str`, useful for handling conventional commits
pub trait FirstLine<'a> {
Expand Down Expand Up @@ -80,7 +81,7 @@ impl<'a> TryFrom<Commit<'a>> for LogEntry<'a> {
/// The different types of version bumps that one can do
///
/// Can be created from a commit message.
#[derive(Debug, Eq, Ord, PartialOrd, PartialEq)]
#[derive(Copy, Clone, Debug, Eq, Ord, PartialOrd, PartialEq)]
pub enum BumpType {
None,
Patch,
Expand Down Expand Up @@ -147,19 +148,21 @@ impl BumpType {
let first_line = commit_msg.first_line();
let conventional_prefix = first_line.prefix();
let breaking = conventional_prefix.contains('!') || commit_msg.contains("\nBREAKING CHANGE");

if breaking {
BumpType::Major
} else if conventional_prefix.starts_with("fix") {
BumpType::Patch
} else if conventional_prefix.starts_with("feat") {
BumpType::Minor
} else {
if !OTHER_TYPES.contains(&conventional_prefix.as_str()) {
error_observer.on_error(commit_msg, first_line);
}
BumpType::None
}
let result =
if breaking {
BumpType::Major
} else if conventional_prefix.starts_with("fix") {
BumpType::Patch
} else if conventional_prefix.starts_with("feat") {
BumpType::Minor
} else {
if !OTHER_TYPES.contains(&conventional_prefix.as_str()) {
error_observer.on_error(commit_msg, first_line);
}
BumpType::None
};
debug!(r#"parsed "{}" into {} bump"#, first_line, result);
result
}
}

Expand Down
22 changes: 19 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use fallible_iterator::FallibleIterator;
use semver::Version;
use simple_error::SimpleError;
use structopt::StructOpt;
use log::warn;
use log::{warn, error};

use crate::bumping::{Bump, BumpType};
use crate::changelog::ChangeLog;
Expand Down Expand Up @@ -78,9 +78,25 @@ impl bumping::ObserveParseError for Vec<ParseError> {
}
}

fn main() -> Result<(), Box<dyn Error>> {
fn main() {
let config: Config = Config::from_args();
stderrlog::new().module(module_path!()).verbosity(config.verbose + 2).init().unwrap();

if let Err(e) = what_bump(config) {
error!("{}", e);
print_error_cause(e.as_ref());
std::process::exit(1);
}
}

fn print_error_cause(error: &dyn Error) {
if let Some(error) = error.source() {
error!("caused by {}", error);
print_error_cause(error);
}
}

fn what_bump(config: Config) -> Result<(), Box<dyn Error>> {
stderrlog::new().module(module_path!()).verbosity(config.verbose + 2).init()?;

match (config.bump, &config.from) {
(Some(ref bump_type), Some(ref version)) => {
Expand Down