mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
chore: rewrite all error messages for consistency (#5176)
Co-authored-by: Roman Krasiuk <rokrassyuk@gmail.com>
This commit is contained in:
@ -6,15 +6,15 @@ use tokio::sync::{mpsc::error::SendError, oneshot::error::RecvError};
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
#[allow(missing_docs)]
|
||||
pub enum DecodePacketError {
|
||||
#[error("Failed to rlp decode: {0:?}")]
|
||||
#[error("failed to rlp decode: {0}")]
|
||||
Rlp(#[from] alloy_rlp::Error),
|
||||
#[error("Received packet len too short.")]
|
||||
#[error("received packet length is too short")]
|
||||
PacketTooShort,
|
||||
#[error("Hash of the header not equals to the hash of the data.")]
|
||||
#[error("header/data hash mismatch")]
|
||||
HashMismatch,
|
||||
#[error("Message id {0} is not supported.")]
|
||||
#[error("message ID {0} is not supported")]
|
||||
UnknownMessage(u8),
|
||||
#[error("Failed to recover public key: {0:?}")]
|
||||
#[error("failed to recover public key: {0}")]
|
||||
Secp256k1(#[from] secp256k1::Error),
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ pub enum DecodePacketError {
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Discv4Error {
|
||||
/// Failed to send a command over the channel
|
||||
#[error("Failed to send on a closed channel")]
|
||||
#[error("failed to send on a closed channel")]
|
||||
Send,
|
||||
/// Failed to receive a command response
|
||||
#[error(transparent)]
|
||||
|
||||
@ -256,26 +256,30 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn to_alloy_rlp_error(e: rlp::DecoderError) -> RlpError {
|
||||
match e {
|
||||
rlp::DecoderError::RlpIsTooShort => RlpError::InputTooShort,
|
||||
rlp::DecoderError::RlpInvalidLength => RlpError::Overflow,
|
||||
rlp::DecoderError::RlpExpectedToBeList => RlpError::UnexpectedString,
|
||||
rlp::DecoderError::RlpExpectedToBeData => RlpError::UnexpectedList,
|
||||
rlp::DecoderError::RlpDataLenWithZeroPrefix |
|
||||
rlp::DecoderError::RlpListLenWithZeroPrefix => RlpError::LeadingZero,
|
||||
rlp::DecoderError::RlpInvalidIndirection => RlpError::NonCanonicalSize,
|
||||
rlp::DecoderError::RlpIncorrectListLen => {
|
||||
RlpError::Custom("incorrect list length when decoding rlp")
|
||||
}
|
||||
rlp::DecoderError::RlpIsTooBig => RlpError::Custom("rlp is too big"),
|
||||
rlp::DecoderError::RlpInconsistentLengthAndData => {
|
||||
RlpError::Custom("inconsistent length and data when decoding rlp")
|
||||
}
|
||||
rlp::DecoderError::Custom(s) => RlpError::Custom(s),
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: EnrKey> Decodable for EnrWrapper<K> {
|
||||
fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
|
||||
let enr = <Enr<K> as rlp::Decodable>::decode(&rlp::Rlp::new(buf))
|
||||
.map_err(|e| match e {
|
||||
rlp::DecoderError::RlpIsTooShort => RlpError::InputTooShort,
|
||||
rlp::DecoderError::RlpInvalidLength => RlpError::Overflow,
|
||||
rlp::DecoderError::RlpExpectedToBeList => RlpError::UnexpectedString,
|
||||
rlp::DecoderError::RlpExpectedToBeData => RlpError::UnexpectedList,
|
||||
rlp::DecoderError::RlpDataLenWithZeroPrefix |
|
||||
rlp::DecoderError::RlpListLenWithZeroPrefix => RlpError::LeadingZero,
|
||||
rlp::DecoderError::RlpInvalidIndirection => RlpError::NonCanonicalSize,
|
||||
rlp::DecoderError::RlpIncorrectListLen => {
|
||||
RlpError::Custom("incorrect list length when decoding rlp")
|
||||
}
|
||||
rlp::DecoderError::RlpIsTooBig => RlpError::Custom("rlp is too big"),
|
||||
rlp::DecoderError::RlpInconsistentLengthAndData => {
|
||||
RlpError::Custom("inconsistent length and data when decoding rlp")
|
||||
}
|
||||
rlp::DecoderError::Custom(s) => RlpError::Custom(s),
|
||||
})
|
||||
.map_err(to_alloy_rlp_error)
|
||||
.map(EnrWrapper::new);
|
||||
if enr.is_ok() {
|
||||
// Decode was successful, advance buffer
|
||||
|
||||
Reference in New Issue
Block a user