From a3b740355057027bc556b02f9791a49317870927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dorian=20P=C3=A9ron?= Date: Sun, 3 Nov 2024 12:29:30 +0100 Subject: [PATCH] feat(checksum): improve FileCheckError variants to be meaningful --- src/uucore/src/lib/features/checksum.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/uucore/src/lib/features/checksum.rs b/src/uucore/src/lib/features/checksum.rs index e7a0a2653..160644046 100644 --- a/src/uucore/src/lib/features/checksum.rs +++ b/src/uucore/src/lib/features/checksum.rs @@ -107,14 +107,16 @@ impl From for LineCheckError { } /// Represents an error that was encountered when processing a checksum file. -#[allow(clippy::enum_variant_names)] enum FileCheckError { /// a generic UError was encountered in sub-functions UError(Box), - /// the error does not stop the processing of next files - NonCriticalError, - /// the error must stop the run of the program - CriticalError, + /// the checksum file is improperly formatted. + ImproperlyFormatted, + /// reading of the checksum file failed + CantOpenChecksumFile, + /// Algorithm detection was unsuccessful. + /// Either none is provided, or there is a conflict. + AlgoDetectionError, } impl From> for FileCheckError { @@ -735,7 +737,7 @@ fn process_checksum_file( // Could not read the file, show the error and continue to the next file show_error!("{e}"); set_exit_code(1); - return Err(FileCheckError::NonCriticalError); + return Err(FileCheckError::CantOpenChecksumFile); } } }; @@ -749,7 +751,7 @@ fn process_checksum_file( }; show_error!("{e}"); set_exit_code(1); - return Err(FileCheckError::NonCriticalError); + return Err(FileCheckError::AlgoDetectionError); }; for (i, line) in lines.iter().enumerate() { @@ -791,7 +793,7 @@ fn process_checksum_file( .into()); } set_exit_code(1); - return Err(FileCheckError::CriticalError); + return Err(FileCheckError::ImproperlyFormatted); } // if any incorrectly formatted line, show it @@ -839,8 +841,8 @@ where use FileCheckError::*; match process_checksum_file(filename_input, algo_name_input, length_input, opts) { Err(UError(e)) => return Err(e), - Err(CriticalError) => break, - Err(NonCriticalError) | Ok(_) => continue, + Err(ImproperlyFormatted) => break, + Err(CantOpenChecksumFile | AlgoDetectionError) | Ok(_) => continue, } }