Skip to content

Commit

Permalink
Avoid a panic when downcasting to redjubjub::Error fails
Browse files Browse the repository at this point in the history
Instead, format the original error as a string, to provide better
diagnostics.

Temporary fix for ZcashFoundation#1357, the permanent fix ticket is ZcashFoundation#1186.
  • Loading branch information
teor2345 committed Nov 24, 2020
1 parent d2173ca commit a765168
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion zebra-consensus/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BoxError> for TransactionError {
fn from(err: BoxError) -> Self {
match err.downcast::<redjubjub::Error>() {
Ok(e) => TransactionError::RedJubjub(*e),
Err(e) => panic!(e),
Err(e) => TransactionError::InternalDowncastError(format!(
"downcast to redjubjub::Error failed, original error: {:?}",
e
)),
}
}
}
Expand Down

0 comments on commit a765168

Please sign in to comment.