rustydht_lib/
errors.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum RustyDHTError {
5    // Failure to parse bytes of a packet
6    #[error("Failed to parse packet bytes: {0}")]
7    PacketParseError(#[from] anyhow::Error),
8
9    #[error("Failed to serialize msg: {0}")]
10    PacketSerializationError(#[from] serde_bencode::Error),
11
12    #[error("General error: {0}")]
13    GeneralError(#[source] anyhow::Error),
14
15    #[error("Connection tracking error: {0}")]
16    ConntrackError(#[source] anyhow::Error),
17
18    #[error("Socket send error: {0}")]
19    SocketSendError(#[source] std::io::Error),
20
21    #[error("Socket recv error: {0}")]
22    SocketRecvError(#[source] std::io::Error),
23
24    #[error("Operation timed out: {0}")]
25    TimeoutError(#[source] anyhow::Error),
26
27    /// This error is a hack for signaling shutdown.
28    /// Don't use unless you're sure you know what you're doing.
29    #[error("It's time to shutdown tasks: {0}")]
30    ShutdownError(#[source] anyhow::Error),
31
32    /// Indicates that the Message type you're trying to build requires more information.
33    #[error("{0} is required")]
34    BuilderMissingFieldError(&'static str),
35
36    /// Indicates that the builder is in an invalid/ambiguous state to build the desired
37    /// Message type.
38    #[error("Builder state invalid: {0}")]
39    BuilderInvalidComboError(&'static str),
40}