use std::fmt;
use std::io;
#[derive(Debug)]
pub enum ContractError {
Io(io::Error),
Parse(String),
NotFound,
}
impl fmt::Display for ContractError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Io(e) => write!(f, "读取契约文件失败: {}", e),
Self::Parse(msg) => write!(f, "契约 YAML 解析失败: {}", msg),
Self::NotFound => write!(f, "契约文件不存在"),
}
}
}
impl std::error::Error for ContractError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Io(e) => Some(e),
_ => None,
}
}
}
impl From<io::Error> for ContractError {
fn from(e: io::Error) -> Self {
Self::Io(e)
}
}