Skip to content

Commit

Permalink
feat: add more information to errors
Browse files Browse the repository at this point in the history
Signed-off-by: Gustavo Inacio <[email protected]>
  • Loading branch information
gusinacio committed Oct 22, 2024
1 parent d83a4a6 commit fd288ef
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
5 changes: 4 additions & 1 deletion crates/header-accumulator/src/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ impl TryFrom<Vec<ExtHeaderRecord>> for Epoch {
.map(|w| w[0].block_number + 1)
.collect();
if !blocks_missing.is_empty() {
return Err(EraValidateError::MissingBlock(blocks_missing));
return Err(EraValidateError::MissingBlock {
blocks: blocks_missing,
epoch: epoch_number,
});
}

// check if all blocks are in the same era
Expand Down
12 changes: 6 additions & 6 deletions crates/header-accumulator/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ pub enum EraValidateError {
#[error("Error validating inclusion proof")]
ProofValidationFailure,

#[error("blocks in epoch must be exactly 8192 units, found {0}")]
#[error("Blocks in epoch must be exactly 8192 units, found {0}")]
InvalidEpochLength(usize),

#[error("block was missing while creating epoch")]
MissingBlock(Vec<u64>),
#[error("Block was missing while creating epoch {epoch}. Missing blocks: {blocks:?}")]
MissingBlock { epoch: u64, blocks: Vec<u64> },

#[error("not all blocks are in the same epoch. epochs found: {0:?}")]
#[error("Not all blocks are in the same epoch. Epochs found: {0:?}")]
InvalidBlockInEpoch(HashSet<u64>),
#[error("Error converting ExtHeaderRecord to header")]
ExtHeaderRecordError,
#[error("Error converting ExtHeaderRecord to header block number {0}")]
ExtHeaderRecordError(u64),
#[error("Invalid block range: {0} - {1}")]
InvalidBlockRange(u64, u64),
#[error("Epoch is in post merge: {0}")]
Expand Down
2 changes: 1 addition & 1 deletion crates/header-accumulator/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl TryFrom<ExtHeaderRecord> for Header {

fn try_from(ext: ExtHeaderRecord) -> Result<Self, Self::Error> {
ext.full_header
.ok_or(EraValidateError::ExtHeaderRecordError)
.ok_or(EraValidateError::ExtHeaderRecordError(ext.block_number))
}
}

Expand Down

0 comments on commit fd288ef

Please sign in to comment.