Skip to content

Commit

Permalink
Produce a more helpful error if creating output file fails
Browse files Browse the repository at this point in the history
  • Loading branch information
robertknight committed Feb 17, 2024
1 parent 5c35d53 commit 949d624
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ocrs-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ fn main() -> Result<(), Box<dyn Error>> {

let write_output_str = |content: String| -> Result<(), Box<dyn Error>> {
if let Some(output_path) = &args.output_path {
std::fs::write(output_path, content.into_bytes())?;
std::fs::write(output_path, content.into_bytes())
.file_error_context("Failed to write output file", output_path)?;
} else {
println!("{}", content);
}
Expand Down Expand Up @@ -309,7 +310,8 @@ fn main() -> Result<(), Box<dyn Error>> {
let Some(output_path) = args.output_path else {
return Err("Output path must be specified when generating annotated PNG".into());
};
write_image(&output_path, annotated_img.view())?;
write_image(&output_path, annotated_img.view())
.file_error_context("Failed to write output file", &output_path)?;
}
}

Expand Down

0 comments on commit 949d624

Please sign in to comment.