Skip to content

Commit

Permalink
feat(blockchain-tree-api): remove manual implementations of core::err…
Browse files Browse the repository at this point in the history
…or::Error (#13332)
  • Loading branch information
TropicalDog17 authored Dec 12, 2024
1 parent 7764b9a commit b19eb79
Showing 1 changed file with 6 additions and 31 deletions.
37 changes: 6 additions & 31 deletions crates/blockchain-tree-api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,42 +166,17 @@ impl std::fmt::Debug for InsertBlockError {
}
}

#[derive(thiserror::Error, Debug)]
#[error("Failed to insert block (hash={}, number={}, parent_hash={}): {kind}",
.block.hash(),
.block.number,
.block.parent_hash)]
struct InsertBlockErrorData {
block: SealedBlock,
#[source]
kind: InsertBlockErrorKind,
}

impl std::fmt::Display for InsertBlockErrorData {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Failed to insert block (hash={}, number={}, parent_hash={}): {}",
self.block.hash(),
self.block.number,
self.block.parent_hash,
self.kind
)
}
}

impl std::fmt::Debug for InsertBlockErrorData {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("InsertBlockError")
.field("error", &self.kind)
.field("hash", &self.block.hash())
.field("number", &self.block.number)
.field("parent_hash", &self.block.parent_hash)
.field("num_txs", &self.block.body.transactions.len())
.finish_non_exhaustive()
}
}

impl core::error::Error for InsertBlockErrorData {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
Some(&self.kind)
}
}

impl InsertBlockErrorData {
const fn new(block: SealedBlock, kind: InsertBlockErrorKind) -> Self {
Self { block, kind }
Expand Down

0 comments on commit b19eb79

Please sign in to comment.