1use thiserror::Error;
2
3#[derive(Error, Debug)]
5pub enum ClamberError {
6 #[error("日志系统错误: {message}")]
8 LoggingError { message: String },
9
10 #[error("创建目录失败: {path}")]
12 DirectoryCreationError { path: String },
13
14 #[error("JWT错误: {message}")]
16 JwtError { message: String },
17
18 #[error("JWT密钥无效: {details}")]
20 JwtKeyError { details: String },
21
22 #[error("JWT签名失败: {details}")]
24 JwtSignError { details: String },
25
26 #[error("JWT验证失败: {details}")]
28 JwtVerifyError { details: String },
29
30 #[error("JWT已过期")]
32 JwtExpiredError,
33
34 #[error("JWT缺少必要字段: {field}")]
36 JwtMissingFieldError { field: String },
37
38 #[error("序列化错误: {details}")]
40 SerializationError { details: String },
41
42 #[error("反序列化错误: {details}")]
44 DeserializationError { details: String },
45
46 #[error("IO错误: {details}")]
48 IoError { details: String },
49
50 #[error("未知错误: {message}")]
52 Other { message: String },
53}
54
55impl From<std::io::Error> for ClamberError {
56 fn from(err: std::io::Error) -> Self {
57 ClamberError::IoError {
58 details: err.to_string(),
59 }
60 }
61}
62
63impl From<serde_json::Error> for ClamberError {
64 fn from(err: serde_json::Error) -> Self {
65 ClamberError::SerializationError {
66 details: err.to_string(),
67 }
68 }
69}
70
71pub type Result<T> = std::result::Result<T, ClamberError>;