herolib-virt 0.3.13

Virtualization and container management for herolib (buildah, nerdctl, kubernetes)
Documentation
//! Error types for SAL Kubernetes operations

use thiserror::Error;

/// Errors that can occur during Kubernetes operations
#[derive(Error, Debug)]
pub enum KubernetesError {
    /// Kubernetes API client error
    #[error("Kubernetes API error: {0}")]
    ApiError(#[from] kube::Error),

    /// Configuration error
    #[error("Configuration error: {0}")]
    ConfigError(String),

    /// Resource not found error
    #[error("Resource not found: {0}")]
    ResourceNotFound(String),

    /// Invalid resource name or pattern
    #[error("Invalid resource name or pattern: {0}")]
    InvalidResourceName(String),

    /// Regular expression error
    #[error("Regular expression error: {0}")]
    RegexError(#[from] regex::Error),

    /// Serialization/deserialization error
    #[error("Serialization error: {0}")]
    SerializationError(#[from] serde_json::Error),

    /// YAML parsing error
    #[error("YAML error: {0}")]
    YamlError(#[from] serde_yaml::Error),

    /// Generic operation error
    #[error("Operation failed: {0}")]
    OperationError(String),

    /// Namespace error
    #[error("Namespace error: {0}")]
    NamespaceError(String),

    /// Permission denied error
    #[error("Permission denied: {0}")]
    PermissionDenied(String),

    /// Timeout error
    #[error("Operation timed out: {0}")]
    Timeout(String),

    /// Generic error wrapper
    #[error("Generic error: {0}")]
    Generic(#[from] anyhow::Error),
}

impl KubernetesError {
    /// Create a new configuration error
    pub fn config_error(msg: impl Into<String>) -> Self {
        Self::ConfigError(msg.into())
    }

    /// Create a new operation error
    pub fn operation_error(msg: impl Into<String>) -> Self {
        Self::OperationError(msg.into())
    }

    /// Create a new namespace error
    pub fn namespace_error(msg: impl Into<String>) -> Self {
        Self::NamespaceError(msg.into())
    }

    /// Create a new permission denied error
    pub fn permission_denied(msg: impl Into<String>) -> Self {
        Self::PermissionDenied(msg.into())
    }

    /// Create a new timeout error
    pub fn timeout(msg: impl Into<String>) -> Self {
        Self::Timeout(msg.into())
    }
}

/// Result type for Kubernetes operations
pub type KubernetesResult<T> = Result<T, KubernetesError>;