Replace some panics with prints

This commit is contained in:
Mateusz Słodkowicz 2024-03-20 16:17:17 +01:00
parent a7c640048a
commit 0d583919e2
Signed by: materus
GPG Key ID: 28D140BCA60B4FD1
1 changed files with 8 additions and 4 deletions

View File

@ -74,7 +74,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
args.currency_from.is_some() && (args.currency_to.is_none() || args.value.is_none()); args.currency_from.is_some() && (args.currency_to.is_none() || args.value.is_none());
if args.interactive && (all_args || wrong_args) { if args.interactive && (all_args || wrong_args) {
panic!("Do not provide codes and value with --interactive") println!("Do not provide codes and value with --interactive");
return Ok(());
} }
if args.recreate_cache || !config::get_cache_path().exists() { if args.recreate_cache || !config::get_cache_path().exists() {
create_cache()?; create_cache()?;
@ -96,7 +97,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.len() .len()
> 0) > 0)
{ {
panic!("API Key is not set up!"); println!("API Key is not set up!");
return Ok(());
} }
if args.list { if args.list {
let currencies = cache::list_currencies()?; let currencies = cache::list_currencies()?;
@ -107,7 +109,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let code = args.list_rates.unwrap().clone(); let code = args.list_rates.unwrap().clone();
let check = check_code(&code)?; let check = check_code(&code)?;
if !check { if !check {
panic!("Code {} not found", code); println!("Code {} not found", code);
return Ok(());
} }
exchange::update_rate(&code).await; exchange::update_rate(&code).await;
let rates = cache::list_rates(&code)?; let rates = cache::list_rates(&code)?;
@ -115,7 +118,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("{} to {} rate: {}", code, rate[0], rate[1]); println!("{} to {} rate: {}", code, rate[0], rate[1]);
} }
} else if wrong_args { } else if wrong_args {
panic!("Not all args specified, provide 'currency from', 'currency to' and 'amount'"); println!("Not all args specified, provide 'currency from', 'currency to' and 'amount'");
return Ok(());
} else if all_args { } else if all_args {
convert_value( convert_value(
&args.currency_from.unwrap().to_uppercase(), &args.currency_from.unwrap().to_uppercase(),