product-os-server 0.0.55

Product OS : Server provides a full functioning advanced server capable of acting as a web server, command and control distributed network, authentication server, crawling server and more. Fully featured with high level of flexibility.
Documentation
//! Error types for Product OS Server
//!
//! Error types for server operations.

use core::fmt;
use alloc::string::String;

/// Errors that can occur during server operations
#[derive(Debug)]
pub enum ProductOSServerError {
    /// A generic error with a descriptive message
    ///
    /// **Deprecated:** Use specific error variants instead
    GenericError(String),
    
    /// Failed to initialize the server
    InitializationError {
        /// The underlying cause of the initialization failure
        reason: String,
    },
    
    /// Failed to configure the server
    ConfigurationError {
        /// The configuration component that failed
        component: String,
        /// The specific error message
        message: String,
    },
    
    /// Controller-related errors
    #[cfg(feature = "controller")]
    ControllerError {
        /// The operation that failed
        operation: String,
        /// The error message
        message: String,
    },
    
    /// Certificate-related errors
    CertificateError {
        /// The error message
        message: String,
    },
    
    /// Executor-related errors
    ExecutorError {
        /// The error message
        message: String,
    },
    
    /// Store-related errors
    #[cfg(feature = "controller")]
    StoreError {
        /// The type of store (relational, key-value, etc.)
        store_type: String,
        /// The error message
        message: String,
    },
    
    /// Timeout errors
    Timeout {
        /// The operation that timed out
        operation: String,
    },
    
    /// Lock acquisition errors
    LockError {
        /// The resource that couldn't be locked
        resource: String,
    },
}

impl fmt::Display for ProductOSServerError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::GenericError(msg) => write!(f, "Server error: {}", msg),
            Self::InitializationError { reason } => {
                write!(f, "Failed to initialize server: {}", reason)
            }
            Self::ConfigurationError { component, message } => {
                write!(f, "Configuration error in {}: {}", component, message)
            }
            #[cfg(feature = "controller")]
            Self::ControllerError { operation, message } => {
                write!(f, "Controller error during {}: {}", operation, message)
            }
            Self::CertificateError { message } => {
                write!(f, "Certificate error: {}", message)
            }
            Self::ExecutorError { message } => {
                write!(f, "Executor error: {}", message)
            }
            #[cfg(feature = "controller")]
            Self::StoreError { store_type, message } => {
                write!(f, "{} store error: {}", store_type, message)
            }
            Self::Timeout { operation } => {
                write!(f, "Operation timed out: {}", operation)
            }
            Self::LockError { resource } => {
                write!(f, "Failed to acquire lock on: {}", resource)
            }
        }
    }
}

#[cfg(feature = "std")]
impl std::error::Error for ProductOSServerError {}

/// Convenience result type for Product OS Server operations
///
/// This type alias provides a shorter way to write `Result<T, ProductOSServerError>`.
///
/// # Examples
///
/// ```
/// use product_os_server::ServerResult;
///
/// fn example_operation() -> ServerResult<String> {
///     Ok("success".to_string())
/// }
/// ```
pub type Result<T> = core::result::Result<T, ProductOSServerError>;