From cb90c6a4adeade07f55e53b1a9aab2969f69527a Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 2 Oct 2022 14:08:11 +0200 Subject: [PATCH] Move some unsafe code and add error implementations --- src/main.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 83b2706..3d9b4c4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,8 +58,27 @@ fn main() { unwrap!(output.write(tex.as_bytes()), "couldn't write output file"); }, Some("pdf") => { - let data = unwrap!(markdown_to_pdf(content), "error while compiling latex, this is most likely a bug"); - unwrap!(output.write(&data), "couldn't write output file"); + match markdown_to_pdf(content) { + Ok(data) => { + match output.write(&data) { + Ok(_) => { + exit(0); + }, + Err(error) => { + eprintln!( + "error while writing file: {}", error + ); + exit(1); + }, + } + }, + Err(error) => { + eprintln!( + "error while compiling latex: {}", error.description() + ); + exit(1); + } + } }, Some(ext) => { eprintln!("unknown file format ({}) for output: {}", ext, output_path.display());