From 2d60c00fb068178d7cb765133d24241575baff9b Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 24 Nov 2020 16:46:02 +1000 Subject: [PATCH] Avoid a panic when downcasting to redjubjub::Error fails (#1363) Instead, format the original error as a string, to provide better diagnostics. Temporary fix for #1357, the permanent fix ticket is #1186. --- zebra-consensus/src/error.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/zebra-consensus/src/error.rs b/zebra-consensus/src/error.rs index caa2f2ed..419dc2e8 100644 --- a/zebra-consensus/src/error.rs +++ b/zebra-consensus/src/error.rs @@ -67,13 +67,20 @@ pub enum TransactionError { #[error("bindingSig MUST represent a valid signature under the transaction binding validating key bvk of SigHash")] RedJubjub(redjubjub::Error), + + // temporary error type until #1186 is fixed + #[error("Downcast from BoxError to redjubjub::Error failed")] + InternalDowncastError(String), } impl From for TransactionError { fn from(err: BoxError) -> Self { match err.downcast::() { Ok(e) => TransactionError::RedJubjub(*e), - Err(e) => panic!(e), + Err(e) => TransactionError::InternalDowncastError(format!( + "downcast to redjubjub::Error failed, original error: {:?}", + e + )), } } }