Cause error on not a number padded_size value

This commit is contained in:
2022-11-27 22:15:30 +01:00
parent d5c9d16bb5
commit 0d3686b7d0
5 changed files with 38 additions and 16 deletions

View File

@@ -10,12 +10,12 @@ pub type Input = Box<dyn Read>;
#[macro_export]
macro_rules! format_if_error {
($result:expr, $format_text:literal) => {
tool_helper::callback_if_error($result, |error_text| {
tool_helper::callback_if_any_error($result, |error_text| {
format!($format_text, error_text=error_text)
})
};
($result:expr, $format_text:literal, $($arg:expr)*) => {
tool_helper::callback_if_error($result, |error_text| {
tool_helper::callback_if_any_error($result, |error_text| {
format!($format_text, $($arg),*, error_text=error_text)
})
};
@@ -139,6 +139,15 @@ pub fn callback_if_error<F: Fn(String) -> String, T>(result: Result<T, Error>, c
}
}
pub fn callback_if_any_error<F: Fn(String) -> String, T, E: std::string::ToString>(result: Result<T, E>, callback: F) -> Result<T, Error> {
match result {
Ok(value) => Ok(value),
Err(error) => {
Err(Error::from_text(callback(error.to_string())))
}
}
}
pub fn open_output_file(output_path: &PathBuf) -> Result<BufWriter<std::fs::File>, Error> {
Ok(std::io::BufWriter::new(std::fs::File::create(output_path)?))
}