quanttide_devops/contract/
error.rs1use std::fmt;
2use std::io;
3
4#[derive(Debug)]
6pub enum ContractError {
7 Io(io::Error),
9 Parse(String),
11 NotFound,
13}
14
15impl fmt::Display for ContractError {
16 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17 match self {
18 Self::Io(e) => write!(f, "读取契约文件失败: {}", e),
19 Self::Parse(msg) => write!(f, "契约 YAML 解析失败: {}", msg),
20 Self::NotFound => write!(f, "契约文件不存在"),
21 }
22 }
23}
24
25impl std::error::Error for ContractError {
26 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
27 match self {
28 Self::Io(e) => Some(e),
29 _ => None,
30 }
31 }
32}
33
34impl From<io::Error> for ContractError {
35 fn from(e: io::Error) -> Self {
36 Self::Io(e)
37 }
38}