From 43328ae653706657b7555b40dd2223e856359fd3 Mon Sep 17 00:00:00 2001 From: raychu86 <14917648+raychu86@users.noreply.github.com> Date: Wed, 27 Mar 2024 11:53:33 -0400 Subject: [PATCH] Add more descriptive error messages --- ledger/puzzle/src/lib.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ledger/puzzle/src/lib.rs b/ledger/puzzle/src/lib.rs index 88f586b63f..b9a0e0679f 100644 --- a/ledger/puzzle/src/lib.rs +++ b/ledger/puzzle/src/lib.rs @@ -231,11 +231,15 @@ impl Puzzle { ) -> Result<()> { // Ensure the epoch hash matches. if solution.epoch_hash() != expected_epoch_hash { - bail!("Solution does not match the expected epoch hash") + bail!( + "Solution does not match the expected epoch hash (found '{}', expected '{expected_epoch_hash}')", + solution.epoch_hash() + ) } // Ensure the solution is greater than or equal to the expected proof target. - if self.get_proof_target(solution)? < expected_proof_target { - bail!("Solution does not meet the proof target requirement") + let proof_target = self.get_proof_target(solution)?; + if proof_target < expected_proof_target { + bail!("Solution does not meet the proof target requirement ({proof_target} < {expected_proof_target})") } Ok(()) } @@ -264,7 +268,7 @@ impl Puzzle { // Ensure the epoch hash matches. cfg_iter!(solutions).try_for_each(|(solution_id, solution)| { if solution.epoch_hash() != expected_epoch_hash { - bail!("Solution '{solution_id}' did not match the expected epoch hash") + bail!("Solution '{solution_id}' did not match the expected epoch hash (found '{}', expected '{expected_epoch_hash}')", solution.epoch_hash()) } Ok(()) })?; @@ -274,7 +278,7 @@ impl Puzzle { cfg_into_iter!(self.get_proof_targets(solutions)?).enumerate().try_for_each(|(i, proof_target)| { if proof_target < expected_proof_target { bail!( - "Solution '{:?}' did not meet the proof target requirement", + "Solution '{:?}' did not meet the proof target requirement ({proof_target} < {expected_proof_target})", solutions.get_index(i).map(|(id, _)| id) ) }