From 949d624441419518d492b8f6c96a71a7be33c63b Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Sat, 17 Feb 2024 07:52:23 +0000 Subject: [PATCH] Produce a more helpful error if creating output file fails --- ocrs-cli/src/main.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ocrs-cli/src/main.rs b/ocrs-cli/src/main.rs index 5d86620..92e60f7 100644 --- a/ocrs-cli/src/main.rs +++ b/ocrs-cli/src/main.rs @@ -279,7 +279,8 @@ fn main() -> Result<(), Box> { let write_output_str = |content: String| -> Result<(), Box> { 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); } @@ -309,7 +310,8 @@ fn main() -> Result<(), Box> { 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)?; } }