1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 12:37:49 +00:00

cksum/hashsum: create a new error type & use it

This commit is contained in:
Sylvestre Ledru 2024-05-29 00:53:53 +02:00
parent bf8b0df22f
commit 193a81bcc3

View file

@ -82,6 +82,7 @@ pub enum ChecksumError {
AlgorithmNotSupportedWithCheck, AlgorithmNotSupportedWithCheck,
CombineMultipleAlgorithms, CombineMultipleAlgorithms,
NeedAlgoToHash, NeedAlgoToHash,
NoProperlyFormattedChecksumLinesFound(String),
} }
impl Error for ChecksumError {} impl Error for ChecksumError {}
@ -131,6 +132,13 @@ impl Display for ChecksumError {
f, f,
"Needs an algorithm to hash with.\nUse --help for more information." "Needs an algorithm to hash with.\nUse --help for more information."
), ),
Self::NoProperlyFormattedChecksumLinesFound(filename) => {
write!(
f,
"{}: no properly formatted checksum lines found",
filename
)
}
} }
} }
} }
@ -341,14 +349,13 @@ fn determine_regex(
} }
} }
Err(io::Error::new( Err(
io::ErrorKind::InvalidData, ChecksumError::NoProperlyFormattedChecksumLinesFound(get_filename_for_output(
format!( filename,
"{}: no properly formatted checksum lines found", input_is_stdin,
get_filename_for_output(filename, input_is_stdin) ))
), .into(),
) )
.into())
} }
/*** /***
@ -552,12 +559,13 @@ where
// return an error // return an error
if !properly_formatted { if !properly_formatted {
if !status { if !status {
show_error!( return Err(ChecksumError::NoProperlyFormattedChecksumLinesFound(
"{}: no properly formatted checksum lines found", get_filename_for_output(filename_input, input_is_stdin),
get_filename_for_output(filename_input, input_is_stdin) )
); .into());
} }
set_exit_code(1); set_exit_code(1);
return Ok(()); return Ok(());
} }