From 5432161bb1ba6414162a8c953d5ea36ea8ca022b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 23 Aug 2020 21:18:55 +0200 Subject: git-sugdiff: Replace `unwrap`s with proper error handling --- src/bin/git-sugdiff.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/bin/git-sugdiff.rs b/src/bin/git-sugdiff.rs index c703e2b..6c96a27 100644 --- a/src/bin/git-sugdiff.rs +++ b/src/bin/git-sugdiff.rs @@ -42,15 +42,27 @@ fn main() { for_suggestion( &config, |suggestion| { - let blob = suggestion.blob().unwrap(); + let blob = match suggestion.blob() { + Ok(b) => b, + Err(e) => { + gseprintln!(e); + process::exit(exitcode::UNAVAILABLE); + }, + }; - Command::new("git") + match Command::new("git") .arg("--no-pager") .arg("diff") .arg(format!("{}:{}", suggestion.commit(), suggestion.path())) .arg(blob.to_string()) .spawn() - .unwrap(); + { + Err(e) => { + gseprintln!(e); + process::exit(exitcode::UNAVAILABLE); + }, + _ => (), + }; }, ); } -- cgit v1.2.3