reth_discv4/
error.rs

1//! Error types that can occur in this crate.
2
3use tokio::sync::{mpsc::error::SendError, oneshot::error::RecvError};
4
5/// Error thrown when decoding a UDP packet.
6#[derive(Debug, thiserror::Error)]
7pub enum DecodePacketError {
8    /// Failed to RLP decode the packet.
9    #[error("failed to rlp decode: {0}")]
10    /// Indicates a failure to RLP decode the packet.
11    Rlp(#[from] alloy_rlp::Error),
12    /// Received packet length is too short.
13    #[error("received packet length is too short")]
14    /// Indicates the received packet length is insufficient.
15    PacketTooShort,
16    /// Header/data hash mismatch.
17    #[error("header/data hash mismatch")]
18    /// Indicates a mismatch between header and data hashes.
19    HashMismatch,
20    /// Unsupported message ID.
21    #[error("message ID {0} is not supported")]
22    /// Indicates an unsupported message ID.
23    UnknownMessage(u8),
24    /// Failed to recover public key.
25    #[error("failed to recover public key: {0}")]
26    /// Indicates a failure to recover the public key.
27    Secp256k1(#[from] secp256k1::Error),
28}
29
30/// High level errors that can occur when interacting with the discovery service
31#[derive(Debug, thiserror::Error)]
32pub enum Discv4Error {
33    /// Failed to send a command over the channel
34    #[error("failed to send on a closed channel")]
35    Send,
36    /// Failed to receive a command response
37    #[error(transparent)]
38    Receive(#[from] RecvError),
39}
40
41impl<T> From<SendError<T>> for Discv4Error {
42    fn from(_: SendError<T>) -> Self {
43        Self::Send
44    }
45}