use std::path::PathBuf;
#[derive(thiserror::Error, Debug)]
pub enum AgentSwitchError {
#[error("未检测到 Agent 工具: {0}")]
AgentNotFound(String),
#[error("配置文件只读,无法修改: {0}")]
ConfigFileReadOnly(PathBuf),
#[error("备份文件损坏: {0}")]
BackupCorrupted(String),
#[error("磁盘空间不足,无法创建备份")]
DiskSpaceInsufficient,
#[error("工具配置错误: {0}")]
ToolConfigError(String),
#[error("模型配置 '{0}' 不存在")]
ModelConfigNotFound(String),
#[error("配置文件不存在: {0}")]
ConfigNotFound(PathBuf),
#[error("IO 错误: {0}")]
Io(#[from] std::io::Error),
#[error("序列化错误: {0}")]
Serialization(String),
#[error("错误: {0}")]
Other(String),
}
impl From<serde_json::Error> for AgentSwitchError {
fn from(err: serde_json::Error) -> Self {
AgentSwitchError::Serialization(err.to_string())
}
}
impl From<toml::de::Error> for AgentSwitchError {
fn from(err: toml::de::Error) -> Self {
AgentSwitchError::Serialization(err.to_string())
}
}
impl From<toml::ser::Error> for AgentSwitchError {
fn from(err: toml::ser::Error) -> Self {
AgentSwitchError::Serialization(err.to_string())
}
}
pub type Result<T> = std::result::Result<T, AgentSwitchError>;