moonpool-transport 0.8.0

FDB-style transport layer for the moonpool framework
Documentation
//! Error types for the moonpool messaging layer.

use crate::UID;

/// Errors that can occur in the messaging layer.
#[derive(Debug, Clone, thiserror::Error)]
#[non_exhaustive]
pub enum MessagingError {
    /// Endpoint not found for the given token.
    #[error("endpoint not found: {token}")]
    EndpointNotFound {
        /// The token that was not found.
        token: UID,
    },

    /// Failed to deserialize a message.
    #[error("deserialization failed: {message}")]
    DeserializationFailed {
        /// Details about the deserialization failure.
        message: String,
    },

    /// Failed to serialize a message.
    #[error("serialization failed: {message}")]
    SerializationFailed {
        /// Details about the serialization failure.
        message: String,
    },

    /// Peer connection error.
    #[error("peer error: {message}")]
    PeerError {
        /// Details about the peer error.
        message: String,
    },

    /// Invalid well-known token index.
    #[error("invalid well-known token: {index} (max: {max})")]
    InvalidWellKnownToken {
        /// The invalid token index.
        index: u32,
        /// Maximum allowed index.
        max: usize,
    },

    /// Invalid state for the requested operation.
    #[error("invalid state: {message}")]
    InvalidState {
        /// Details about the invalid state.
        message: String,
    },

    /// Network operation failed.
    #[error("network error: {message}")]
    NetworkError {
        /// Details about the network error.
        message: String,
    },

    /// Builder missing required local address.
    #[error("local_address is required - call .local_address(addr) before .build()")]
    MissingLocalAddress,
}

impl From<serde_json::Error> for MessagingError {
    fn from(err: serde_json::Error) -> Self {
        MessagingError::DeserializationFailed {
            message: err.to_string(),
        }
    }
}

impl From<crate::PeerError> for MessagingError {
    fn from(err: crate::PeerError) -> Self {
        MessagingError::PeerError {
            message: err.to_string(),
        }
    }
}