pluggable 0.1.0

A comprehensive, async plugin system for Rust applications with dependency management and security
Documentation
//! Error types for the plugin system

use thiserror::Error;

/// Main error type for the plugin system
#[derive(Error, Debug)]
pub enum PluginError {
    #[error("Plugin initialization failed: {0}")]
    InitializationFailed(String),

    #[error("Plugin execution failed: {0}")]
    ExecutionFailed(String),

    #[error("Plugin cleanup failed: {0}")]
    CleanupFailed(String),

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

    #[error("Dependency not satisfied: {plugin} requires {dependency}")]
    DependencyNotSatisfied { plugin: String, dependency: String },

    #[error("Permission denied: {plugin} lacks permission for {action}")]
    PermissionDenied { plugin: String, action: String },

    #[error("Plugin not found: {0}")]
    PluginNotFound(String),

    #[error("Invalid plugin metadata: {0}")]
    InvalidMetadata(String),

    #[error("Serialization error: {0}")]
    SerializationError(String),

    #[error("IO error: {0}")]
    IoError(String),

    #[error("Sandbox error: {0}")]
    SandboxError(String),

    #[error("Event error: {0}")]
    EventError(String),

    #[error("Validation error: {0}")]
    ValidationError(String),

    #[error("Execution error: {0}")]
    ExecutionError(String),
}

impl Clone for PluginError {
    fn clone(&self) -> Self {
        match self {
            Self::InitializationFailed(msg) => Self::InitializationFailed(msg.clone()),
            Self::ExecutionFailed(msg) => Self::ExecutionFailed(msg.clone()),
            Self::CleanupFailed(msg) => Self::CleanupFailed(msg.clone()),
            Self::ConfigurationError(msg) => Self::ConfigurationError(msg.clone()),
            Self::DependencyNotSatisfied { plugin, dependency } => Self::DependencyNotSatisfied {
                plugin: plugin.clone(),
                dependency: dependency.clone(),
            },
            Self::PermissionDenied { plugin, action } => Self::PermissionDenied {
                plugin: plugin.clone(),
                action: action.clone(),
            },
            Self::PluginNotFound(msg) => Self::PluginNotFound(msg.clone()),
            Self::InvalidMetadata(msg) => Self::InvalidMetadata(msg.clone()),
            Self::SerializationError(msg) => Self::SerializationError(msg.clone()),
            Self::IoError(msg) => Self::IoError(msg.clone()),
            Self::SandboxError(msg) => Self::SandboxError(msg.clone()),
            Self::EventError(msg) => Self::EventError(msg.clone()),
            Self::ValidationError(msg) => Self::ValidationError(msg.clone()),
            Self::ExecutionError(msg) => Self::ExecutionError(msg.clone()),
        }
    }
}

impl From<serde_json::Error> for PluginError {
    fn from(err: serde_json::Error) -> Self {
        Self::SerializationError(err.to_string())
    }
}

impl From<std::io::Error> for PluginError {
    fn from(err: std::io::Error) -> Self {
        Self::IoError(err.to_string())
    }
}

/// Result type alias for plugin operations
pub type PluginResult<T> = Result<T, PluginError>;