use std::fmt;
use std::sync::Arc;
use crate::external::ExternalAnalyzerError;
pub type PluginResult<T> = Result<T, PluginError>;
#[derive(Debug, Clone)]
pub enum PluginError {
External(Arc<ExternalAnalyzerError>),
InitializationFailed { name: String, reason: String },
InvalidResult { plugin: String, operation: String, reason: String },
Configuration { plugin: String, reason: String },
Internal { reason: String },
}
impl fmt::Display for PluginError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PluginError::External(error) => write!(f, "External plugin error: {error}"),
PluginError::InitializationFailed { name, reason } => {
write!(f, "Plugin '{name}' failed to initialize: {reason}")
}
PluginError::InvalidResult { plugin, operation, reason } => {
write!(f, "Plugin '{plugin}' returned invalid result for '{operation}': {reason}")
}
PluginError::Configuration { plugin, reason } => {
write!(f, "Plugin '{plugin}' configuration error: {reason}")
}
PluginError::Internal { reason } => {
write!(f, "Internal plugin error: {reason}")
}
}
}
}
impl std::error::Error for PluginError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::External(error) => Some(error.as_ref()),
_ => None,
}
}
}
impl From<Arc<ExternalAnalyzerError>> for PluginError {
fn from(error: Arc<ExternalAnalyzerError>) -> Self {
Self::External(error)
}
}
impl From<ExternalAnalyzerError> for PluginError {
fn from(error: ExternalAnalyzerError) -> Self {
Self::External(Arc::new(error))
}
}