imporved error handling

This commit is contained in:
2023-01-21 17:13:13 +01:00
parent b38bb186b1
commit 85f55c9d51
4 changed files with 80 additions and 22 deletions

View File

@@ -0,0 +1,33 @@
use std::process;
use super::Builder;
pub struct AsciiDoctorBuilder;
impl Builder for AsciiDoctorBuilder {
fn build(&self, in_path: &str, out_path: &str) -> Result<(), String> {
let result = process::Command::new("asciidoctor")
.arg(format!("{in_path}"))
.arg(format!("--out-file={out_path}"))
.output();
if let Ok(success) = result {
if success.stderr.len() == 0 {
return Ok(());
} else {
return Err(AsciiDoctorBuilder::from_utf8(success.stderr));
}
} else {
return Err("command failed to execute".to_string());
}
}
}
impl AsciiDoctorBuilder {
fn from_utf8(input: Vec<u8>) -> String {
return match String::from_utf8(input) {
Ok(m) => m,
Err(e) => panic!("could not print error message: {}", e),
};
}
}