ant-node 0.21.0

Pure quantum-proof network node for the Autonomi decentralized network
Documentation
//! Error types for ant-node.

use thiserror::Error;

/// Result type alias using the crate's Error type.
pub type Result<T> = std::result::Result<T, Error>;

/// Errors that can occur in ant-node.
#[derive(Error, Debug)]
pub enum Error {
    /// Configuration error.
    #[error("configuration error: {0}")]
    Config(String),

    /// Node startup error.
    #[error("node startup failed: {0}")]
    Startup(String),

    /// Network error from the core networking layer.
    #[error("network error: {0}")]
    Network(String),

    /// Storage error.
    #[error("storage error: {0}")]
    Storage(String),

    /// Payment error.
    #[error("payment error: {0}")]
    Payment(String),

    /// Upgrade error.
    #[error("upgrade error: {0}")]
    Upgrade(String),

    /// Cryptographic error.
    #[error("crypto error: {0}")]
    Crypto(String),

    /// I/O error.
    #[error("I/O error: {0}")]
    Io(#[from] std::io::Error),

    /// Serialization error.
    #[error("serialization error: {0}")]
    Serialization(String),

    /// Protocol error.
    #[error("protocol error: {0}")]
    Protocol(String),

    /// Invalid chunk error.
    #[error("invalid chunk: {0}")]
    InvalidChunk(String),

    /// Replication error.
    #[error("replication error: {0}")]
    Replication(String),

    /// Node is shutting down.
    #[error("node is shutting down")]
    ShuttingDown,
}

impl From<ant_protocol::pointer::PointerError> for Error {
    /// Map a wire-level pointer rejection onto the node's error type.
    ///
    /// Signature failures become [`Error::Crypto`] and everything else becomes
    /// [`Error::Protocol`], so a caller can still tell "these bytes are not a
    /// pointer" from "these bytes are not signed by the key they carry".
    fn from(error: ant_protocol::pointer::PointerError) -> Self {
        use ant_protocol::pointer::PointerError;
        match error {
            PointerError::SignatureInvalid | PointerError::SigningFailed(_) => {
                Self::Crypto(error.to_string())
            }
            other => Self::Protocol(other.to_string()),
        }
    }
}