From 05bc296243cff9b61cb9f7d820f5bb8742b8d3f3 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 2 Aug 2020 05:45:23 +0200 Subject: for_suggestion: Replace `unwrap`s with exits Print the error and exit. --- src/suggestion.rs | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/suggestion.rs b/src/suggestion.rs index 9617a00..fc22a7c 100644 --- a/src/suggestion.rs +++ b/src/suggestion.rs @@ -29,23 +29,53 @@ where F: Fn(&Suggestion) }, }; - let client = Client::new( + let client = match Client::new( &config.github_token, &o_r.owner, &o_r.repo, - ).unwrap(); + ) { + Ok(c) => c, + Err(e) => { + gseprintln!(e); + process::exit(exitcode::SOFTWARE); + }, + }; - client.fetch(&suggestion_arg).unwrap() + match client.fetch(&suggestion_arg) { + Ok(s) => s, + Err(e) => { + gseprintln!(e); + process::exit(exitcode::UNAVAILABLE); + }, + } } else { - let url: SuggestionUrl = suggestion_arg.parse().unwrap(); + let url: SuggestionUrl = match suggestion_arg.parse() { + Ok(u) => u, + Err(e) => { + gseprintln!(e); + process::exit(exitcode::USAGE); + }, + }; - let client = Client::new( + let client = match Client::new( &config.github_token, &url.owner, &url.repo, - ).unwrap(); + ) { + Ok(c) => c, + Err(e) => { + gseprintln!(e); + process::exit(exitcode::SOFTWARE); + }, + }; - client.fetch(&url.comment_id).unwrap() + match client.fetch(&url.comment_id) { + Ok(s) => s, + Err(e) => { + gseprintln!(e); + process::exit(exitcode::UNAVAILABLE); + }, + } }; f(&suggestion); -- cgit v1.2.3