Skip to main content

ass_core/plugin/
error.rs

1//! Error types and result alias for plugin operations.
2//!
3//! Defines [`PluginError`] for registration and processing failures along with
4//! the crate-local [`Result`] alias used throughout the plugin system.
5
6use alloc::string::String;
7use core::fmt;
8
9/// Errors that can occur during plugin operations
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub enum PluginError {
12    /// Handler with same name already registered
13    DuplicateHandler(String),
14    /// Handler not found for given name
15    HandlerNotFound(String),
16    /// Plugin processing failed
17    ProcessingFailed(String),
18    /// Invalid plugin configuration
19    InvalidConfig(String),
20}
21
22impl fmt::Display for PluginError {
23    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24        match self {
25            Self::DuplicateHandler(name) => {
26                write!(f, "Handler '{name}' already registered")
27            }
28            Self::HandlerNotFound(name) => {
29                write!(f, "Handler '{name}' not found")
30            }
31            Self::ProcessingFailed(msg) => {
32                write!(f, "Plugin processing failed: {msg}")
33            }
34            Self::InvalidConfig(msg) => {
35                write!(f, "Invalid plugin configuration: {msg}")
36            }
37        }
38    }
39}
40
41#[cfg(feature = "std")]
42impl std::error::Error for PluginError {}
43
44/// Result type for plugin operations
45pub type Result<T> = core::result::Result<T, PluginError>;