mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-07-22 05:25:14 +08:00
111 lines
2.7 KiB
Rust
111 lines
2.7 KiB
Rust
//! 适配器错误类型
|
|
//!
|
|
//! 定义适配器层的错误类型,提供更详细的错误信息
|
|
|
|
use thiserror::Error;
|
|
|
|
/// 适配器错误类型
|
|
#[derive(Error, Debug)]
|
|
pub enum AdapterError {
|
|
/// Unity 版本不支持
|
|
#[error("Unsupported Unity version: {0}")]
|
|
UnsupportedUnityVersion(String),
|
|
|
|
/// AssetBundle 解析错误
|
|
#[error("Failed to parse AssetBundle: {0}")]
|
|
AssetBundleParseError(String),
|
|
|
|
/// Manifest 解析错误
|
|
#[error("Failed to parse Manifest: {0}")]
|
|
ManifestParseError(String),
|
|
|
|
/// 找不到合适的适配器
|
|
#[error("No suitable adapter found for {0}")]
|
|
NoSuitableAdapter(String),
|
|
|
|
/// 客户端未找到
|
|
#[error("Game client not found at: {0}")]
|
|
ClientNotFound(String),
|
|
|
|
/// 客户端版本不匹配
|
|
#[error("Client version mismatch: expected {expected}, found {found}")]
|
|
VersionMismatch {
|
|
/// 期望的版本
|
|
expected: String,
|
|
/// 实际的版本
|
|
found: String,
|
|
},
|
|
|
|
/// 备份操作失败
|
|
#[error("Backup operation failed: {0}")]
|
|
BackupFailed(String),
|
|
|
|
/// 恢复操作失败
|
|
#[error("Restore operation failed: {0}")]
|
|
RestoreFailed(String),
|
|
|
|
/// 完整性验证失败
|
|
#[error("Integrity check failed: {0}")]
|
|
IntegrityCheckFailed(String),
|
|
|
|
/// I/O 错误
|
|
#[error("I/O error: {0}")]
|
|
Io(#[from] std::io::Error),
|
|
|
|
/// 核心错误
|
|
#[error("Core error: {0}")]
|
|
Core(#[from] bat_core::Error),
|
|
|
|
/// 其他错误
|
|
#[error("{0}")]
|
|
Other(String),
|
|
}
|
|
|
|
/// 适配器 Result 类型
|
|
pub type Result<T> = std::result::Result<T, AdapterError>;
|
|
|
|
impl From<String> for AdapterError {
|
|
fn from(s: String) -> Self {
|
|
AdapterError::Other(s)
|
|
}
|
|
}
|
|
|
|
impl From<&str> for AdapterError {
|
|
fn from(s: &str) -> Self {
|
|
AdapterError::Other(s.to_string())
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_unsupported_unity_version() {
|
|
let err = AdapterError::UnsupportedUnityVersion("2022.1.0".to_string());
|
|
assert!(err.to_string().contains("2022.1.0"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_version_mismatch() {
|
|
let err = AdapterError::VersionMismatch {
|
|
expected: "1.0.0".to_string(),
|
|
found: "2.0.0".to_string(),
|
|
};
|
|
assert!(err.to_string().contains("expected 1.0.0"));
|
|
assert!(err.to_string().contains("found 2.0.0"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_from_string() {
|
|
let err: AdapterError = "test error".to_string().into();
|
|
assert!(matches!(err, AdapterError::Other(_)));
|
|
}
|
|
|
|
#[test]
|
|
fn test_from_str() {
|
|
let err: AdapterError = "test error".into();
|
|
assert!(matches!(err, AdapterError::Other(_)));
|
|
}
|
|
}
|