From 0c0072f1cd16850c648bd5ccd694971e4e24f5b4 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 17 Sep 2020 00:34:44 +0200 Subject: main.rs: Remove `unwrap()`s and handle errors --- src/main.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index cb3b77c..780ab62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,13 @@ fn main() { }, }; - let repo = Repository::open(".").unwrap(); + let repo = match Repository::open(".") { + Ok(r) => r, + Err(e) => { + eprintln(&format!("unable to open repository: {}", e)); + process::exit(exitcode::NOINPUT); + }, + }; let todos = Todos { repo: &repo }; @@ -55,7 +61,13 @@ fn main() { } }; - todos.write_since(tree, &mut std::io::stdout()).unwrap(); + match todos.write_since(tree, &mut std::io::stdout()) { + Err(e) => { + eprintln(&e); + process::exit(exitcode::UNAVAILABLE); + }, + _ => (), + }; } /// Print to standard error with a program-specific prefix. -- cgit v1.2.3