Clean up error handling

This commit is contained in:
2022-11-27 22:32:14 +01:00
parent 0a48078345
commit 4fbeb80c60
3 changed files with 10 additions and 27 deletions

View File

@@ -1,6 +1,6 @@
use tool_helper::{Input, Output};
use std::io::Read;
pub use tool_helper::Error;
pub use tool_helper::{Error, format_if_error};
pub enum LineFeed {
Unix,
@@ -92,12 +92,11 @@ pub fn convert(cfg: Configuration, input: Input, mut output: Output) -> Result<(
}
};
let action = String::from("Writing source file");
if is_source_file {
Error::try_or_new_with_action(action, write_source_file(input, &mut output, declarations, cfg.data_name, line_feed))
format_if_error!(write_source_file(input, &mut output, declarations, cfg.data_name, line_feed), "Writing source file failed with: \"{error_text}\"")
}
else {
Error::try_or_new_with_action(action, write_header_file(input, &mut output, cfg.file_name, declarations, cfg.data_name, line_feed))
format_if_error!(write_header_file(input, &mut output, cfg.file_name, declarations, cfg.data_name, line_feed), "Writing header file failed with: \"{error_text}\"")
}
}