Make it clearer which extrinsic failed to decode (#1835)

* Add an extrinsic index to decode errors so that we know which extrinsic failed

* Fix subxt::BlockError to align with subxt_core::BlockError

---------

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
This commit is contained in:
James Wilson
2024-10-23 17:03:32 +01:00
committed by GitHub
parent 2f7ea3ff64
commit 15cf58f723
3 changed files with 72 additions and 19 deletions
+28 -6
View File
@@ -172,18 +172,40 @@ pub enum BlockError {
#[error("Could not find a block with hash {0} (perhaps it was on a non-finalized fork?)")]
NotFound(String),
/// Leftover bytes found after decoding the extrinsic.
#[error("After decoding, {0} bytes were left, suggesting that decoding may have failed")]
LeftoverBytes(usize),
#[error("After decoding the exntrinsic at index {extrinsic_index}, {num_leftover_bytes} bytes were left, suggesting that decoding may have failed")]
LeftoverBytes {
/// Index of the extrinsic that failed to decode.
extrinsic_index: usize,
/// Number of bytes leftover after decoding the extrinsic.
num_leftover_bytes: usize,
},
/// Decoding error.
#[error("Cannot decode extrinsic: {0}")]
ExtrinsicDecodeError(subxt_core::error::ExtrinsicDecodeError),
#[error("Cannot decode extrinsic at index {extrinsic_index}: {error}")]
ExtrinsicDecodeError {
/// Index of the extrinsic that failed to decode.
extrinsic_index: usize,
/// The decode error.
error: subxt_core::error::ExtrinsicDecodeError,
},
}
impl From<CoreBlockError> for BlockError {
fn from(value: CoreBlockError) -> Self {
match value {
CoreBlockError::LeftoverBytes(n) => BlockError::LeftoverBytes(n),
CoreBlockError::ExtrinsicDecodeError(e) => BlockError::ExtrinsicDecodeError(e),
CoreBlockError::LeftoverBytes {
extrinsic_index,
num_leftover_bytes,
} => BlockError::LeftoverBytes {
extrinsic_index,
num_leftover_bytes,
},
CoreBlockError::ExtrinsicDecodeError {
extrinsic_index,
error,
} => BlockError::ExtrinsicDecodeError {
extrinsic_index,
error,
},
}
}
}