use thiserror::Error;
#[derive(Debug, Error)]
pub enum PluginManagerError {
#[error("插件未找到: {0}")]
NotFound(String),
#[error("插件已存在: {0}")]
AlreadyExists(String),
#[error("插件验证失败: {0}")]
ValidationFailed(String),
#[error("插件加载失败: {0}")]
LoadFailed(String),
#[error("插件初始化失败: {0}")]
InitializationFailed(String),
#[error("插件启动失败: {0}")]
StartFailed(String),
#[error("插件停止失败: {0}")]
StopFailed(String),
#[error("插件卸载失败: {0}")]
UninstallFailed(String),
#[error("插件升级失败: {0}")]
UpgradeFailed(String),
#[error("插件包解析失败: {0}")]
ParseFailed(String),
#[error("插件包完整性验证失败: {0}")]
IntegrityCheckFailed(String),
#[error("插件包签名验证失败: {0}")]
SignatureCheckFailed(String),
#[error("插件依赖错误: {0}")]
DependencyError(String),
#[error("插件状态错误: {0}")]
StateError(String),
#[error("插件配置错误: {0}")]
ConfigError(String),
#[error("插件执行错误: {0}")]
ExecutionError(String),
#[error("IO 错误: {0}")]
Io(#[from] std::io::Error),
#[error("JSON 错误: {0}")]
Json(#[from] serde_json::Error),
#[error("其他错误: {0}")]
Other(String),
}
impl PluginManagerError {
pub fn not_found(plugin_id: impl Into<String>) -> Self {
Self::NotFound(plugin_id.into())
}
pub fn already_exists(plugin_id: impl Into<String>) -> Self {
Self::AlreadyExists(plugin_id.into())
}
pub fn validation_failed(msg: impl Into<String>) -> Self {
Self::ValidationFailed(msg.into())
}
pub fn load_failed(msg: impl Into<String>) -> Self {
Self::LoadFailed(msg.into())
}
pub fn initialization_failed(msg: impl Into<String>) -> Self {
Self::InitializationFailed(msg.into())
}
pub fn start_failed(msg: impl Into<String>) -> Self {
Self::StartFailed(msg.into())
}
pub fn stop_failed(msg: impl Into<String>) -> Self {
Self::StopFailed(msg.into())
}
pub fn dependency_error(msg: impl Into<String>) -> Self {
Self::DependencyError(msg.into())
}
pub fn state_error(msg: impl Into<String>) -> Self {
Self::StateError(msg.into())
}
pub fn config_error(msg: impl Into<String>) -> Self {
Self::ConfigError(msg.into())
}
pub fn execution_error(msg: impl Into<String>) -> Self {
Self::ExecutionError(msg.into())
}
}
pub type PluginManagerResult<T> = Result<T, PluginManagerError>;