Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@harsh-ps-2003
Copy link

@harsh-ps-2003 harsh-ps-2003 commented Apr 15, 2025

Improve the error handling by using thiserror for core::error::Error implementations.

Fixes #90

/// The actual size of the RLP node in bytes
size: usize,
/// The maximum allowed size in bytes
max: usize,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this field seems redundant since max will always be 33, no?

Comment on lines +44 to +47
ProofVerification(
/// The reason for verification failure
String
),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ProofVerification(
/// The reason for verification failure
String
),
ProofVerification(#[from] ProofVerificationError),

seems like you missed to replace this

Comment on lines +51 to +56
HashMismatch {
/// The expected hash value
expected: String,
/// The actual hash value found
found: String,
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should probably be B256, no?

Comment on lines +7 to +12
/// Error during RLP encoding/decoding
#[error("RLP error: {0}")]
RlpError(
/// The underlying RLP error
#[from] alloy_rlp::Error
),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hints at flawed design if we need to have this variant converting alloy_rlp::Error to TrieError as well as the reverse conversion bellow TrieError to alloy_rlp::Error. seems like this variant should be removed.

Comment on lines +66 to +69
stack.push(RlpNode::from_raw_rlp(&bytes[..len]).map_err(|e| match e {
TrieError::RlpNodeTooLarge { .. } => alloy_rlp::Error::Custom("RLP node too large"),
_ => alloy_rlp::Error::Custom("unexpected error decoding RLP node"),
})?);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like this change can be reverted since the conversion From<TrieError> for alloy_rlp::Error was implemented

Comment on lines +17 to +22
Self::from_raw_rlp(bytes).map_err(|e| match e {
TrieError::RlpNodeTooLarge { size: _, max: _ } => {
alloy_rlp::Error::Custom("RLP node too large")
}
_ => alloy_rlp::Error::Custom("unexpected error decoding RLP node"),
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, can just propagate now

Comment on lines +68 to +72
pub fn from_raw_rlp(data: &[u8]) -> Result<Self, TrieError> {
Self::from_raw(data).ok_or_else(|| TrieError::RlpNodeTooLarge {
size: data.len(),
max: MAX,
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes more sense if this returns alloy_rlp::Result<Self> still and just do TrieError::RlpNodeTooLarge.into()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use thiserror for core::error::Error implementations

2 participants