From 1e0395babf66013387576d54aa311ca67f2af0a3 Mon Sep 17 00:00:00 2001 From: Richa Jain Date: Fri, 13 Sep 2024 13:11:43 +0800 Subject: [PATCH] In case of an error it, log the error in the file and continue to process other rows --- ipa-core/src/cli/crypto.rs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/ipa-core/src/cli/crypto.rs b/ipa-core/src/cli/crypto.rs index 2f77238d0d..d483a00c47 100644 --- a/ipa-core/src/cli/crypto.rs +++ b/ipa-core/src/cli/crypto.rs @@ -180,7 +180,7 @@ pub async fn decrypt_and_reconstruct(args: DecryptArgs) -> Result<(), BoxError> .create_new(true) .open(args.output_file)?, ); - + let mut first_error = None; for (idx, (dec_report1, (dec_report2, dec_report3))) in decrypted_reports1 .zip(decrypted_reports2.zip(decrypted_reports3)) .enumerate() @@ -236,11 +236,33 @@ pub async fn decrypt_and_reconstruct(args: DecryptArgs) -> Result<(), BoxError> trigger_value, )?; } - _ => println!("Decryption failed for record no {idx}"), + (Err(e1), _, _) => { + writeln!(writer, "Decryption failed Record: {idx} Reason:{e1}",)?; + eprintln!("Decryption failed Record: {idx} Reason:{e1}"); + if first_error.is_none() { + first_error = Some(e1); + } + } + (Ok(_), Err(e2), _) => { + writeln!(writer, "Decryption failed Record: {idx} Reason:{e2}",)?; + eprintln!("Decryption failed Record: {idx} Reason:{e2}"); + if first_error.is_none() { + first_error = Some(e2); + } + } + (Ok(_), Ok(_), Err(e3)) => { + writeln!(writer, "Decryption failed Record: {idx} Reason:{e3}",)?; + eprintln!("Decryption failed Record: {idx} Reason:{e3}"); + if first_error.is_none() { + first_error = Some(e3); + } + } } } - - Ok(()) + match first_error { + None => return Ok(()), + Some(err) => return Err(Box::new(err)), + } } #[cfg(test)]