Skip to content

Commit

Permalink
remove expect panics and return error instead
Browse files Browse the repository at this point in the history
  • Loading branch information
jqnatividad committed Oct 10, 2022
1 parent 2e74397 commit 6539764
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/cmd/enumerate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
} else if args.flag_constant.is_some() {
headers.push_field(b"constant");
} else if copy_operation {
let current_header = String::from_utf8(headers[copy_index].to_vec())
.expect("Could not parse cell as utf-8!");
let current_header = match String::from_utf8(headers[copy_index].to_vec()) {
Ok(s) => s,
Err(e) => return fail_format!("Could not parse cell as utf-8! - {e}"),
};
headers.push_field(format!("{current_header}_copy").as_bytes());
} else {
headers.push_field(b"index");
Expand Down
6 changes: 4 additions & 2 deletions src/cmd/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,10 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
if was_cached {
redis_cache_hits += 1;
}
final_response = serde_json::from_str(&intermediate_redis_value)
.expect("Cannot deserialize Redis cache value. Try flushing the Redis cache with --flushdb.");
final_response = match serde_json::from_str(&intermediate_redis_value) {
Ok(r) => r,
Err(e)=> return fail_format!("Cannot deserialize Redis cache value. Try flushing the Redis cache with --flushdb - {e}"),
};
if !args.flag_cache_error && final_response.status_code != 200 {
let key = format!(
"{}{:?}{}{}{}",
Expand Down
6 changes: 4 additions & 2 deletions src/cmd/fetchpost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,10 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
if was_cached {
redis_cache_hits += 1;
}
final_response = serde_json::from_str(&intermediate_redis_value)
.expect("Cannot deserialize Redis cache value. Try flushing the Redis cache with --flushdb.");
final_response = match serde_json::from_str(&intermediate_redis_value) {
Ok(r) => r,
Err(e)=> return fail_format!("Cannot deserialize Redis cache value. Try flushing the Redis cache with --flushdb - {e}"),
};
if !args.flag_cache_error && final_response.status_code != 200 {
let key = format!(
"{}{:?}{}{}{}",
Expand Down

0 comments on commit 6539764

Please sign in to comment.