Skip to main content

ant_node/
error.rs

1//! Error types for ant-node.
2
3use thiserror::Error;
4
5/// Result type alias using the crate's Error type.
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Errors that can occur in ant-node.
9#[derive(Error, Debug)]
10pub enum Error {
11    /// Configuration error.
12    #[error("configuration error: {0}")]
13    Config(String),
14
15    /// Node startup error.
16    #[error("node startup failed: {0}")]
17    Startup(String),
18
19    /// Network error from the core networking layer.
20    #[error("network error: {0}")]
21    Network(String),
22
23    /// Storage error.
24    #[error("storage error: {0}")]
25    Storage(String),
26
27    /// Payment error.
28    #[error("payment error: {0}")]
29    Payment(String),
30
31    /// Upgrade error.
32    #[error("upgrade error: {0}")]
33    Upgrade(String),
34
35    /// Cryptographic error.
36    #[error("crypto error: {0}")]
37    Crypto(String),
38
39    /// I/O error.
40    #[error("I/O error: {0}")]
41    Io(#[from] std::io::Error),
42
43    /// Serialization error.
44    #[error("serialization error: {0}")]
45    Serialization(String),
46
47    /// Protocol error.
48    #[error("protocol error: {0}")]
49    Protocol(String),
50
51    /// Invalid chunk error.
52    #[error("invalid chunk: {0}")]
53    InvalidChunk(String),
54
55    /// Replication error.
56    #[error("replication error: {0}")]
57    Replication(String),
58
59    /// Node is shutting down.
60    #[error("node is shutting down")]
61    ShuttingDown,
62}
63
64impl From<ant_protocol::pointer::PointerError> for Error {
65    /// Map a wire-level pointer rejection onto the node's error type.
66    ///
67    /// Signature failures become [`Error::Crypto`] and everything else becomes
68    /// [`Error::Protocol`], so a caller can still tell "these bytes are not a
69    /// pointer" from "these bytes are not signed by the key they carry".
70    fn from(error: ant_protocol::pointer::PointerError) -> Self {
71        use ant_protocol::pointer::PointerError;
72        match error {
73            PointerError::SignatureInvalid | PointerError::SigningFailed(_) => {
74                Self::Crypto(error.to_string())
75            }
76            other => Self::Protocol(other.to_string()),
77        }
78    }
79}