mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
feat(checksum): improve FileCheckError variants to be meaningful
This commit is contained in:
parent
c7798d5d20
commit
a3b7403550
1 changed files with 12 additions and 10 deletions
|
@ -107,14 +107,16 @@ impl From<ChecksumError> for LineCheckError {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents an error that was encountered when processing a checksum file.
|
/// Represents an error that was encountered when processing a checksum file.
|
||||||
#[allow(clippy::enum_variant_names)]
|
|
||||||
enum FileCheckError {
|
enum FileCheckError {
|
||||||
/// a generic UError was encountered in sub-functions
|
/// a generic UError was encountered in sub-functions
|
||||||
UError(Box<dyn UError>),
|
UError(Box<dyn UError>),
|
||||||
/// the error does not stop the processing of next files
|
/// the checksum file is improperly formatted.
|
||||||
NonCriticalError,
|
ImproperlyFormatted,
|
||||||
/// the error must stop the run of the program
|
/// reading of the checksum file failed
|
||||||
CriticalError,
|
CantOpenChecksumFile,
|
||||||
|
/// Algorithm detection was unsuccessful.
|
||||||
|
/// Either none is provided, or there is a conflict.
|
||||||
|
AlgoDetectionError,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Box<dyn UError>> for FileCheckError {
|
impl From<Box<dyn UError>> for FileCheckError {
|
||||||
|
@ -735,7 +737,7 @@ fn process_checksum_file(
|
||||||
// Could not read the file, show the error and continue to the next file
|
// Could not read the file, show the error and continue to the next file
|
||||||
show_error!("{e}");
|
show_error!("{e}");
|
||||||
set_exit_code(1);
|
set_exit_code(1);
|
||||||
return Err(FileCheckError::NonCriticalError);
|
return Err(FileCheckError::CantOpenChecksumFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -749,7 +751,7 @@ fn process_checksum_file(
|
||||||
};
|
};
|
||||||
show_error!("{e}");
|
show_error!("{e}");
|
||||||
set_exit_code(1);
|
set_exit_code(1);
|
||||||
return Err(FileCheckError::NonCriticalError);
|
return Err(FileCheckError::AlgoDetectionError);
|
||||||
};
|
};
|
||||||
|
|
||||||
for (i, line) in lines.iter().enumerate() {
|
for (i, line) in lines.iter().enumerate() {
|
||||||
|
@ -791,7 +793,7 @@ fn process_checksum_file(
|
||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
set_exit_code(1);
|
set_exit_code(1);
|
||||||
return Err(FileCheckError::CriticalError);
|
return Err(FileCheckError::ImproperlyFormatted);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if any incorrectly formatted line, show it
|
// if any incorrectly formatted line, show it
|
||||||
|
@ -839,8 +841,8 @@ where
|
||||||
use FileCheckError::*;
|
use FileCheckError::*;
|
||||||
match process_checksum_file(filename_input, algo_name_input, length_input, opts) {
|
match process_checksum_file(filename_input, algo_name_input, length_input, opts) {
|
||||||
Err(UError(e)) => return Err(e),
|
Err(UError(e)) => return Err(e),
|
||||||
Err(CriticalError) => break,
|
Err(ImproperlyFormatted) => break,
|
||||||
Err(NonCriticalError) | Ok(_) => continue,
|
Err(CantOpenChecksumFile | AlgoDetectionError) | Ok(_) => continue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue