Skip to content

Commit

Permalink
fix: avoid using the format ident capturing Rust feature
Browse files Browse the repository at this point in the history
  • Loading branch information
tranzystorekk authored and oknozor committed Mar 9, 2022
1 parent b6bda19 commit 4c8c8ca
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 30 deletions.
10 changes: 7 additions & 3 deletions src/conventional/changelog/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ impl Display for ChangelogError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
ChangelogError::TemplateNotFound(path) => {
writeln!(f, "changelog template not found in {path:?}")
writeln!(f, "changelog template not found in {:?}", path)
}
ChangelogError::TeraError(err) => {
writeln!(f, "failed to render changelog: \n\t{}", err)
}
ChangelogError::WriteError(err) => {
writeln!(f, "failed to write changelog: \n\t{}", err)
}
ChangelogError::TeraError(err) => writeln!(f, "failed to render changelog: \n\t{err}"),
ChangelogError::WriteError(err) => writeln!(f, "failed to write changelog: \n\t{err}"),
ChangelogError::SeparatorNotFound(path) => writeln!(
f,
"cannot find default separator '- - -' in {}",
Expand Down
24 changes: 16 additions & 8 deletions src/conventional/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ impl Display for BumpError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
writeln!(f, "failed to bump version\n")?;
match self {
BumpError::Git2Error(err) => writeln!(f, "\t{err}"),
BumpError::TagError(err) => writeln!(f, "\t{err}"),
BumpError::SemVerError(err) => writeln!(f, "\t{err}"),
BumpError::Git2Error(err) => writeln!(f, "\t{}", err),
BumpError::TagError(err) => writeln!(f, "\t{}", err),
BumpError::SemVerError(err) => writeln!(f, "\t{}", err),
BumpError::NoCommitFound => writeln!(
f,
r#"cause: No conventional commit found to bump current version.
Expand Down Expand Up @@ -80,13 +80,18 @@ impl Display for ConventionalCommitError {
let error_header = "Errored commit: ".bold().red();
let author = format!("<{}>", author).blue();
let cause = anyhow!(cause.clone());
let cause = format!("{cause:?}")
let cause = format!("{:?}", cause)
.lines()
.collect::<Vec<&str>>()
.join("\n\t");

writeln!(
f, "{error_header}{oid} {author}\n\t{message_title}'{summary}'\n\t{cause_title}{cause}",
f,
"{}{} {}\n\t{message_title}'{summary}'\n\t{cause_title}{}",
error_header,
oid,
author,
cause,
message_title = "Commit message: ".yellow().bold(),
summary = summary.italic(),
cause_title = "Error: ".yellow().bold(),
Expand All @@ -99,10 +104,13 @@ impl Display for ConventionalCommitError {
author,
} => {
let error_header = "Errored commit: ".bold().red();
let author = format!("<{author}>").blue();
let author = format!("<{}>", author).blue();
writeln!(
f,
"{error_header}{oid} {author}\n\t{message}'{summary}'\n\t{cause}Commit type `{commit_type}` not allowed",
"{}{} {}\n\t{message}'{summary}'\n\t{cause}Commit type `{commit_type}` not allowed",
error_header,
oid,
author,
message = "Commit message:".yellow().bold(),
cause = "Error:".yellow().bold(),
summary = summary.italic(),
Expand All @@ -111,7 +119,7 @@ impl Display for ConventionalCommitError {
}
ConventionalCommitError::ParseError(err) => {
let err = anyhow!(err.clone());
writeln!(f, "{err:?}")
writeln!(f, "{:?}", err)
}
}
}
Expand Down
25 changes: 13 additions & 12 deletions src/git/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ impl Display for Git2Error {
match self {
Git2Error::NothingToCommit { branch, statuses } => {
if let Some(branch) = branch {
writeln!(f, "On branch {branch}\n")?;
writeln!(f, "On branch {}\n", branch)?;
}

match statuses {
Some(statuses) if !statuses.0.is_empty() => write!(f, "{statuses}"),
Some(statuses) if !statuses.0.is_empty() => write!(f, "{}", statuses),
_ => writeln!(
f,
"nothing to commit (create/copy files and use \"git add\" to track)"
Expand Down Expand Up @@ -109,8 +109,9 @@ impl Display for Git2Error {
Git2Error::StatusError(_) => writeln!(f, "failed to get git statuses"),
Git2Error::ChangesNeedToBeCommitted(statuses) => writeln!(
f,
"{}{statuses}",
"Cannot create tag: changes need to be committed".red()
"{}{}",
"Cannot create tag: changes need to be committed".red(),
statuses
),
}?;

Expand All @@ -123,7 +124,7 @@ impl Display for Git2Error {
| Git2Error::StashError(err)
| Git2Error::StatusError(err)
| Git2Error::Other(err)
| Git2Error::CommitNotFound(err) => writeln!(f, "\ncause: {err}"),
| Git2Error::CommitNotFound(err) => writeln!(f, "\ncause: {}", err),
_ => fmt::Result::Ok(()),
}
}
Expand All @@ -133,23 +134,23 @@ impl Display for TagError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
TagError::SemVerError { tag, err } => {
writeln!(f, "tag `{tag}` is not SemVer compliant")?;
writeln!(f, "\tcause: {err}")
writeln!(f, "tag `{}` is not SemVer compliant", tag)?;
writeln!(f, "\tcause: {}", err)
}
TagError::InvalidPrefixError { prefix, tag } => {
writeln!(f, "Expected a tag with prefix {prefix}, got {tag}")
writeln!(f, "Expected a tag with prefix {}, got {}", prefix, tag)
}
TagError::NotFound { tag, err } => {
writeln!(f, "tag {tag} not found")?;
writeln!(f, "\tcause: {err}")
writeln!(f, "tag {} not found", tag)?;
writeln!(f, "\tcause: {}", err)
}
TagError::NoTag => writeln!(f, "unable to get any tag"),
TagError::NoMatchFound { pattern, err } => {
match pattern {
None => writeln!(f, "no tag found")?,
Some(pattern) => writeln!(f, "no tag matching pattern {pattern}")?,
Some(pattern) => writeln!(f, "no tag matching pattern {}", pattern)?,
}
writeln!(f, "\tcause: {err}")
writeln!(f, "\tcause: {}", err)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/hook/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl Hook {
#[cfg(target_family = "unix")]
{
let args = args.iter().join(" ");
let cmd = format!("{cmd} {args}");
let cmd = format!("{} {}", cmd, args);

let status = Command::new("sh").arg("-c").arg(cmd).status()?;

Expand Down
23 changes: 17 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn init<S: AsRef<Path> + ?Sized>(path: &S) -> Result<()> {

if !path.exists() {
std::fs::create_dir(&path)
.map_err(|err| anyhow!("failed to create directory `{path:?}` \n\ncause:{err}"))?;
.map_err(|err| anyhow!("failed to create directory `{:?}` \n\ncause: {}", path, err))?;
}

let mut is_init_commit = false;
Expand Down Expand Up @@ -96,9 +96,15 @@ pub fn init<S: AsRef<Path> + ?Sized>(path: &S) -> Result<()> {
std::fs::write(
&settings_path,
toml::to_string(&settings)
.map_err(|err| anyhow!("failed to serialize {CONFIG_PATH}\n\ncause: {err}"))?,
.map_err(|err| anyhow!("failed to serialize {}\n\ncause: {}", CONFIG_PATH, err))?,
)
.map_err(|err| anyhow!("failed to write file `{settings_path:?}`\n\ncause: {err}"))?;
.map_err(|err| {
anyhow!(
"failed to write file `{:?}`\n\ncause: {}",
settings_path,
err
)
})?;
}

repository.add_all()?;
Expand Down Expand Up @@ -426,7 +432,12 @@ impl CocoGitto {
glob.is_match(&branch)
});

ensure!(is_match, "No patterns matched in {whitelist:?} for branch '{branch}', bump is not allowed")
ensure!(
is_match,
"No patterns matched in {:?} for branch '{}', bump is not allowed",
whitelist,
branch
)
}
};

Expand All @@ -437,7 +448,7 @@ impl CocoGitto {
println!("Failed to get current version, falling back to 0.0.0");
Version::new(0, 0, 0)
}
Err(ref err) => bail!("{err}"),
Err(ref err) => bail!("{}", err),
};

let mut next_version = increment.bump(&current_version, &self.repository)?;
Expand All @@ -450,7 +461,7 @@ impl CocoGitto {
cause_key, comparison
);

bail!("{}:\n\t{cause}\n", "SemVer Error".red().to_string());
bail!("{}:\n\t{}\n", "SemVer Error".red().to_string(), cause);
};

if let Some(pre_release) = pre_release {
Expand Down

0 comments on commit 4c8c8ca

Please sign in to comment.