From 3d574d8adccd1e757989bf199faeaa97273fc700 Mon Sep 17 00:00:00 2001 From: natalie Date: Wed, 19 Jul 2023 14:06:49 +0100 Subject: [PATCH] Improve error handling in Coordinator (#48) --- coordinator/src/cli.rs | 2 +- coordinator/src/step_2.rs | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/coordinator/src/cli.rs b/coordinator/src/cli.rs index e75e3281..d7a615e0 100644 --- a/coordinator/src/cli.rs +++ b/coordinator/src/cli.rs @@ -17,7 +17,7 @@ pub fn cli( "=== STEP 2: CHOOSE MESSAGE AND GENERATE COMMITMENT PACKAGE ===\n" )?; - let signing_package = step_2(reader, logger, participants_config.participants.clone()); + let signing_package = step_2(reader, logger, participants_config.participants.clone())?; writeln!(logger, "=== STEP 3: BUILD GROUP SIGNATURE ===\n")?; diff --git a/coordinator/src/step_2.rs b/coordinator/src/step_2.rs index 42965a9d..54765633 100644 --- a/coordinator/src/step_2.rs +++ b/coordinator/src/step_2.rs @@ -17,10 +17,10 @@ pub fn step_2( input: &mut impl BufRead, logger: &mut dyn Write, participants: Vec, -) -> SigningPackage { - let signing_package = request_inputs_commitments(input, logger, participants).unwrap(); +) -> Result> { + let signing_package = request_inputs_commitments(input, logger, participants)?; print_commitments(logger, &signing_package); - signing_package + Ok(signing_package) } // Input required: @@ -37,7 +37,7 @@ fn request_inputs_commitments( let mut msg = String::new(); input.read_line(&mut msg)?; - let message = hex::decode(msg.trim()).unwrap(); //TODO: handle error + let message = hex::decode(msg.trim())?; writeln!(logger, "The number of signers: ")?; @@ -48,8 +48,7 @@ fn request_inputs_commitments( logger, "Please enter JSON encoded commitments for participant {:#?}:", p - ) - .unwrap(); // TODO: improve printing + )?; // TODO: improve printing let mut commitments_input = String::new(); input.read_line(&mut commitments_input)?;