NAC_Blockchain/nac-cli/src/error.rs

66 lines
1.3 KiB
Rust

use thiserror::Error;
#[derive(Error, Debug)]
#[allow(dead_code)]
pub enum CliError {
#[error("配置错误: {0}")]
Config(String),
#[error("网络错误: {0}")]
Network(String),
#[error("账户错误: {0}")]
Account(String),
#[error("交易错误: {0}")]
Transaction(String),
#[error("合约错误: {0}")]
Contract(String),
#[error("宪法错误: {0}")]
Constitution(String),
#[error("节点错误: {0}")]
Node(String),
#[error("区块错误: {0}")]
Block(String),
#[error("密码学错误: {0}")]
Crypto(String),
#[error("编码错误: {0}")]
Encoding(String),
#[error("IO错误: {0}")]
Io(String),
#[error("JSON错误: {0}")]
Json(#[from] serde_json::Error),
#[error("YAML错误: {0}")]
Yaml(#[from] serde_yaml::Error),
#[error("TOML错误: {0}")]
Toml(#[from] toml::de::Error),
#[error("HTTP错误: {0}")]
Http(#[from] reqwest::Error),
#[error("无效输入: {0}")]
InvalidInput(String),
#[error("其他错误: {0}")]
Other(String),
}
pub type Result<T> = std::result::Result<T, CliError>;
// 添加From<std::io::Error>转换
impl From<std::io::Error> for CliError {
fn from(err: std::io::Error) -> Self {
CliError::Io(err.to_string())
}
}