mirror of
https://github.com/uutils/coreutils
synced 2024-12-14 07:12:44 +00:00
cksum/hashsum: create a new error type & use it
This commit is contained in:
parent
bf8b0df22f
commit
193a81bcc3
1 changed files with 19 additions and 11 deletions
|
@ -82,6 +82,7 @@ pub enum ChecksumError {
|
|||
AlgorithmNotSupportedWithCheck,
|
||||
CombineMultipleAlgorithms,
|
||||
NeedAlgoToHash,
|
||||
NoProperlyFormattedChecksumLinesFound(String),
|
||||
}
|
||||
|
||||
impl Error for ChecksumError {}
|
||||
|
@ -131,6 +132,13 @@ impl Display for ChecksumError {
|
|||
f,
|
||||
"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(
|
||||
io::ErrorKind::InvalidData,
|
||||
format!(
|
||||
"{}: no properly formatted checksum lines found",
|
||||
get_filename_for_output(filename, input_is_stdin)
|
||||
),
|
||||
Err(
|
||||
ChecksumError::NoProperlyFormattedChecksumLinesFound(get_filename_for_output(
|
||||
filename,
|
||||
input_is_stdin,
|
||||
))
|
||||
.into(),
|
||||
)
|
||||
.into())
|
||||
}
|
||||
|
||||
/***
|
||||
|
@ -552,12 +559,13 @@ where
|
|||
// return an error
|
||||
if !properly_formatted {
|
||||
if !status {
|
||||
show_error!(
|
||||
"{}: no properly formatted checksum lines found",
|
||||
get_filename_for_output(filename_input, input_is_stdin)
|
||||
);
|
||||
return Err(ChecksumError::NoProperlyFormattedChecksumLinesFound(
|
||||
get_filename_for_output(filename_input, input_is_stdin),
|
||||
)
|
||||
.into());
|
||||
}
|
||||
set_exit_code(1);
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue