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.
This commit is contained in:
teor 2020-11-24 16:46:02 +10:00 committed by GitHub
parent 6202cb45b1
commit 2d60c00fb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -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
)),
}
}
}