Proper error handling for the exporter

This commit is contained in:
sharkdp 2018-03-20 21:12:33 +01:00 committed by David Peter
parent 9b5dd60a92
commit 1bd5436109
2 changed files with 8 additions and 9 deletions

View File

@ -13,14 +13,7 @@ pub struct JsonExporter {}
impl Exporter for JsonExporter { impl Exporter for JsonExporter {
fn serialize(&self, results: &Vec<ExportEntry>) -> Result<String> { fn serialize(&self, results: &Vec<ExportEntry>) -> Result<String> {
let serialized = to_string_pretty(&HyperfineSummary { results }); to_string_pretty(&HyperfineSummary { results }).map_err(|e| Error::new(ErrorKind::Other, e))
serialized.map_err(|e| {
Error::new(
ErrorKind::Other,
format!("Error while serializing to JSON: {:}", e),
)
})
} }
} }

View File

@ -207,7 +207,13 @@ fn main() {
match res { match res {
Ok(timing_results) => { Ok(timing_results) => {
export_manager.write_results(timing_results).unwrap(); let ans = export_manager.write_results(timing_results);
if let Err(e) = ans {
error(&format!(
"The following error occured while exporting: {}",
e.description()
));
}
} }
Err(e) => error(e.description()), Err(e) => error(e.description()),
} }