From 65397647c99d8ef434e70adf049383347b365759 Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Mon, 10 Oct 2022 09:02:12 -0400 Subject: [PATCH] remove expect panics and return error instead --- src/cmd/enumerate.rs | 6 ++++-- src/cmd/fetch.rs | 6 ++++-- src/cmd/fetchpost.rs | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/cmd/enumerate.rs b/src/cmd/enumerate.rs index 9a7eacde7..c0e6bae26 100644 --- a/src/cmd/enumerate.rs +++ b/src/cmd/enumerate.rs @@ -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"); diff --git a/src/cmd/fetch.rs b/src/cmd/fetch.rs index 2e1e4edfe..564311404 100644 --- a/src/cmd/fetch.rs +++ b/src/cmd/fetch.rs @@ -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!( "{}{:?}{}{}{}", diff --git a/src/cmd/fetchpost.rs b/src/cmd/fetchpost.rs index acba10ccc..a855fee19 100644 --- a/src/cmd/fetchpost.rs +++ b/src/cmd/fetchpost.rs @@ -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!( "{}{:?}{}{}{}",