1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use thiserror::Error;

#[derive(Error, Debug)]
pub enum RustyDHTError {
    // Failure to parse bytes of a packet
    #[error("Failed to parse packet bytes: {0}")]
    PacketParseError(#[from] anyhow::Error),

    #[error("Failed to serialize msg: {0}")]
    PacketSerializationError(#[from] serde_bencode::Error),

    #[error("General error: {0}")]
    GeneralError(#[source] anyhow::Error),

    #[error("Connection tracking error: {0}")]
    ConntrackError(#[source] anyhow::Error),

    #[error("Socket send error: {0}")]
    SocketSendError(#[source] std::io::Error),

    #[error("Socket recv error: {0}")]
    SocketRecvError(#[source] std::io::Error),

    #[error("Operation timed out: {0}")]
    TimeoutError(#[source] anyhow::Error),

    /// This error is a hack for signaling shutdown.
    /// Don't use unless you're sure you know what you're doing.
    #[error("It's time to shutdown tasks: {0}")]
    ShutdownError(#[source] anyhow::Error),

    /// Indicates that the Message type you're trying to build requires more information.
    #[error("{0} is required")]
    BuilderMissingFieldError(&'static str),

    /// Indicates that the builder is in an invalid/ambiguous state to build the desired
    /// Message type.
    #[error("Builder state invalid: {0}")]
    BuilderInvalidComboError(&'static str),
}