Improve Error
This commit is contained in:
@@ -92,11 +92,12 @@ 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(write_source_file(input, &mut output, declarations, cfg.data_name, line_feed), None)
|
||||
Error::try_or_new_with_action(action, write_source_file(input, &mut output, declarations, cfg.data_name, line_feed))
|
||||
}
|
||||
|
||||
else {
|
||||
Error::try_or_new(write_header_file(input, &mut output, cfg.file_name, declarations, cfg.data_name, line_feed), None)
|
||||
Error::try_or_new_with_action(action, write_header_file(input, &mut output, cfg.file_name, declarations, cfg.data_name, line_feed))
|
||||
}
|
||||
}
|
@@ -15,9 +15,9 @@ struct CommandLine {
|
||||
output_file: PathBuf,
|
||||
}
|
||||
|
||||
fn configurate(cmd: &mut CommandLine) -> tool_helper::Result<Configuration> {
|
||||
fn configurate(cmd: &mut CommandLine) -> Result<Configuration, Error> {
|
||||
let file_name = tool_helper::get_file_name_from_path_buf(&cmd.output_file, "output")?;
|
||||
let extension = tool_helper::os_str_to_string(Error::ok_or_new(cmd.output_file.extension(), ||"File extension required for output".to_owned(), None)?, "extension")?.to_ascii_lowercase();
|
||||
let extension = tool_helper::os_str_to_string(Error::ok_or_new(cmd.output_file.extension(), ||"File extension required for output".to_owned())?, "extension")?.to_ascii_lowercase();
|
||||
let file_type = Error::ok_or_new({
|
||||
match extension.as_ref() {
|
||||
"h" => Some(FileType::CHeader),
|
||||
@@ -26,12 +26,12 @@ fn configurate(cmd: &mut CommandLine) -> tool_helper::Result<Configuration> {
|
||||
"cpp" => Some(FileType::CPPSource),
|
||||
_ => None
|
||||
}
|
||||
}, ||format!("{} unkown file extension", extension), None)?;
|
||||
}, ||format!("{} unkown file extension", extension))?;
|
||||
|
||||
Ok(Configuration{file_name, data_name: std::mem::take(&mut cmd.data_name), line_feed: cpp_out::LineFeed::Windows, file_type})
|
||||
}
|
||||
|
||||
fn run_main() -> tool_helper::Result<()> {
|
||||
fn run_main() -> Result<(), Error> {
|
||||
match CommandLine::try_parse() {
|
||||
Ok(mut cmd) => {
|
||||
let cfg = configurate(&mut cmd)?;
|
||||
@@ -40,7 +40,7 @@ fn run_main() -> tool_helper::Result<()> {
|
||||
|
||||
return cpp_out::convert(cfg, input, output);
|
||||
},
|
||||
Err(error) => Err(tool_helper::Error::new(error.to_string(), None))
|
||||
Err(error) => Err(tool_helper::Error::from_error(error))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ fn main() {
|
||||
match run_main() {
|
||||
Ok(_) => (),
|
||||
Err(error) => {
|
||||
eprintln!("{}", error.text);
|
||||
eprintln!("{}", error);
|
||||
std::process::exit(error.exit_code);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user