From 70bdfc4e997be3bd0f887660a0f6b69d8c39fa84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20M=2E=20Bezerra?= Date: Sat, 15 Oct 2022 22:06:40 -0300 Subject: [PATCH] improve fatal error message --- src/commands/mod.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 6198604..474ea89 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -182,13 +182,19 @@ pub fn run( // about whether the command succeeded without such a message info!(accessible, "Successfully compressed '{}'.", to_utf(&output_path)); } else { + // If Ok(false) or Err() occurred, delete incomplete file at `output_path` + // + // if deleting fails, print an extra alert message pointing + // out that we left a possibly CORRUPTED file at `output_path` if let Err(_) = utils::remove_file_or_dir(&output_path) { eprintln!("{red}FATAL ERROR:\n", red = *colors::RED); - eprintln!(" Please manually delete '{}'.", to_utf(&output_path)); - eprintln!( - " Compression failed and we could not delete '{}'.", - to_utf(&output_path), - ); + eprintln!(" Ouch failed to delete the file '{}'.", to_utf(&output_path)); + eprintln!(" Please delete it manually."); + eprintln!(" This file is corrupted if compression didn't finished."); + + if let Err(_) = compress_result { + eprintln!(" Compression failed for reasons below."); + } } }