59 lines
1.5 KiB
Rust
59 lines
1.5 KiB
Rust
//! 桥接错误类型定义
|
|
|
|
use std::fmt;
|
|
|
|
/// 桥接错误类型
|
|
#[derive(Debug)]
|
|
pub enum BridgeError {
|
|
/// 网络错误
|
|
Network(String),
|
|
|
|
/// 无效的证明
|
|
InvalidProof(String),
|
|
|
|
/// 插件错误
|
|
PluginError(String),
|
|
|
|
/// 验证错误
|
|
ValidationError(String),
|
|
|
|
/// 安全错误
|
|
SecurityError(String),
|
|
|
|
/// 存储错误
|
|
StorageError(String),
|
|
|
|
/// 序列化错误
|
|
SerializationError(String),
|
|
}
|
|
|
|
impl fmt::Display for BridgeError {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
BridgeError::Network(msg) => write!(f, "Network error: {}", msg),
|
|
BridgeError::InvalidProof(msg) => write!(f, "Invalid proof: {}", msg),
|
|
BridgeError::PluginError(msg) => write!(f, "Plugin error: {}", msg),
|
|
BridgeError::ValidationError(msg) => write!(f, "Validation error: {}", msg),
|
|
BridgeError::SecurityError(msg) => write!(f, "Security error: {}", msg),
|
|
BridgeError::StorageError(msg) => write!(f, "Storage error: {}", msg),
|
|
BridgeError::SerializationError(msg) => write!(f, "Serialization error: {}", msg),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::error::Error for BridgeError {}
|
|
|
|
/// 桥接结果类型
|
|
pub type BridgeResult<T> = Result<T, BridgeError>;
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_error_display() {
|
|
let err = BridgeError::Network("Connection failed".to_string());
|
|
assert_eq!(err.to_string(), "Network error: Connection failed");
|
|
}
|
|
}
|