aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2020-08-02 05:45:23 +0200
committerTeddy Wing2020-08-02 05:45:23 +0200
commit05bc296243cff9b61cb9f7d820f5bb8742b8d3f3 (patch)
tree14d522f90f9b56c2d46505fa00f03d014204eb51
parent74b68435b29b18f0bed423ec1b7d011ad41d8031 (diff)
downloadgit-suggestion-05bc296243cff9b61cb9f7d820f5bb8742b8d3f3.tar.bz2
for_suggestion: Replace `unwrap`s with exits
Print the error and exit.
-rw-r--r--src/suggestion.rs44
1 files changed, 37 insertions, 7 deletions
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);