From fd288ef9f7ed57fd6327b7c6834b699e96c96ea2 Mon Sep 17 00:00:00 2001 From: Gustavo Inacio Date: Tue, 22 Oct 2024 21:20:43 +0200 Subject: [PATCH] feat: add more information to errors Signed-off-by: Gustavo Inacio --- crates/header-accumulator/src/epoch.rs | 5 ++++- crates/header-accumulator/src/errors.rs | 12 ++++++------ crates/header-accumulator/src/types.rs | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/crates/header-accumulator/src/epoch.rs b/crates/header-accumulator/src/epoch.rs index 90c14909..221bf47f 100644 --- a/crates/header-accumulator/src/epoch.rs +++ b/crates/header-accumulator/src/epoch.rs @@ -53,7 +53,10 @@ impl TryFrom> 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 diff --git a/crates/header-accumulator/src/errors.rs b/crates/header-accumulator/src/errors.rs index 558335ab..12f65021 100644 --- a/crates/header-accumulator/src/errors.rs +++ b/crates/header-accumulator/src/errors.rs @@ -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), + #[error("Block was missing while creating epoch {epoch}. Missing blocks: {blocks:?}")] + MissingBlock { epoch: u64, blocks: Vec }, - #[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), - #[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}")] diff --git a/crates/header-accumulator/src/types.rs b/crates/header-accumulator/src/types.rs index daa4125c..7c713b16 100644 --- a/crates/header-accumulator/src/types.rs +++ b/crates/header-accumulator/src/types.rs @@ -32,7 +32,7 @@ impl TryFrom for Header { fn try_from(ext: ExtHeaderRecord) -> Result { ext.full_header - .ok_or(EraValidateError::ExtHeaderRecordError) + .ok_or(EraValidateError::ExtHeaderRecordError(ext.block_number)) } }