Skip to content

Commit

Permalink
fix(cli): fix broken pipe when stdout is interrupted (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Dec 26, 2023
1 parent f635bae commit bdce4b5
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions git-cliff-core/src/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ impl<'a> Changelog<'a> {
pub fn generate<W: Write>(&self, out: &mut W) -> Result<()> {
debug!("Generating changelog...");
if let Some(header) = &self.config.changelog.header {
write!(out, "{header}")?;
let write_result = write!(out, "{header}");
if let Err(e) = write_result {
if e.kind() != std::io::ErrorKind::BrokenPipe {
return Err(e.into());
}
}
}
let postprocessors = self
.config
Expand All @@ -149,14 +154,19 @@ impl<'a> Changelog<'a> {
.clone()
.unwrap_or_default();
for release in &self.releases {
write!(
let write_result = write!(
out,
"{}",
self.body_template.render(release, &postprocessors)?
)?;
);
if let Err(e) = write_result {
if e.kind() != std::io::ErrorKind::BrokenPipe {
return Err(e.into());
}
}
}
if let Some(footer_template) = &self.footer_template {
writeln!(
let write_result = writeln!(
out,
"{}",
footer_template.render(
Expand All @@ -165,7 +175,12 @@ impl<'a> Changelog<'a> {
},
&postprocessors,
)?
)?;
);
if let Err(e) = write_result {
if e.kind() != std::io::ErrorKind::BrokenPipe {
return Err(e.into());
}
}
}
Ok(())
}
Expand Down

0 comments on commit bdce4b5

Please sign in to comment.