parliament 0.1.0

Protocols, traits, and domain logic for graceful governance.
Documentation
use thiserror::Error;

/// A top-level Result type for the Parliament ecosystem, using our custom Error.
pub type Result<T> = std::result::Result<T, Error>;

/// The primary error type for all Parliament operations.
#[derive(Error, Debug)]
pub enum Error {
    /// An error originating from an underlying infrastructure component.
    #[error("infrastructure error: {0}")]
    Infrastructure(#[from] Box<dyn std::error::Error + Send + Sync>),

    /// A received payload could not be deserialized or was malformed.
    #[error("failed to decode payload: {0}")]
    PayloadDecode(String),

    /// An operation was attempted on a resource that could not be found.
    #[error("resource '{id}' of type '{resource_type}' not found")]
    ResourceNotFound { resource_type: String, id: String },

    /// An operation was attempted with an unknown or unauthorized Signet.
    #[error("unrecognized or unauthorized signet: {0}")]
    UnknownSignet(String),

    /// An operation was attempted on a Hunt that was not in a valid state.
    #[error("invalid vigil state for operation: {0}")]
    InvalidVigilState(String),

    /// A request-reply operation timed out.
    #[error("request timed out after {duration:?}")]
    RequestTimeout { duration: std::time::Duration },

    /// FIX: Added this variant to handle validation in the `make_id!` macro.
    /// An identifier was found to be invalid (e.g., empty).
    #[error("invalid identifier for type '{0}': cannot be empty")]
    InvalidIdentifier(String),

    /// A generic, unrecoverable error. Use sparingly.
    #[error("an unrecoverable error occurred: {0}")]
    Unrecoverable(String),
}

impl Error {
    /// A convenience constructor for wrapping infrastructure errors.
    pub fn from_infra<E>(err: E) -> Self
    where
        E: std::error::Error + Send + Sync + 'static,
    {
        Error::Infrastructure(Box::new(err))
    }
}