From ad3c31588ba00a06aae1129cad967403e04c5fe7 Mon Sep 17 00:00:00 2001 From: natalie Date: Thu, 18 May 2023 14:01:31 +0100 Subject: [PATCH] Make error handling more semantic in main (#326) --- src/main.rs | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/main.rs b/src/main.rs index d739a7e..2856d65 100755 --- a/src/main.rs +++ b/src/main.rs @@ -15,12 +15,9 @@ use crate::trusted_dealer_keygen::trusted_dealer_keygen; fn main() -> io::Result<()> { let mut reader = Box::new(io::stdin().lock()); let config = request_inputs(&mut reader); - match config { - Ok(_) => (), - Err(e) => { - eprintln!("Error: {}", e); - std::process::exit(exitcode::DATAERR) - } + if let Err(e) = config { + eprintln!("Error: {}", e); + std::process::exit(exitcode::DATAERR) } let config = config.unwrap(); @@ -28,22 +25,16 @@ fn main() -> io::Result<()> { let mut rng = thread_rng(); let valid = validate_inputs(&config); - match valid { - Ok(_) => (), - Err(e) => { - eprintln!("Error: {}", e); - std::process::exit(exitcode::DATAERR) - } + if let Err(e) = valid { + eprintln!("Error: {}", e); + std::process::exit(exitcode::DATAERR) } // Print outputs let out = trusted_dealer_keygen(config, &mut rng); - match out { - Ok(_) => (), - Err(e) => { - eprintln!("Error: {}", e); - std::process::exit(1) - } + if let Err(e) = out { + eprintln!("Error: {}", e); + std::process::exit(1) } let (key_packages, pubkeys) = out.unwrap();