burncloud_auto_update/
error.rs1use std::fmt;
4
5#[derive(Debug)]
7pub enum UpdateError {
8 Network(String),
10 GitHub(String),
12 Version(String),
14 FileSystem(String),
16 Permission(String),
18 Configuration(String),
20 Other(String),
22 Unknown(String),
24}
25
26impl fmt::Display for UpdateError {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 match self {
29 UpdateError::Network(msg) => write!(f, "网络错误: {}", msg),
30 UpdateError::GitHub(msg) => write!(f, "GitHub API 错误: {}", msg),
31 UpdateError::Version(msg) => write!(f, "版本解析错误: {}", msg),
32 UpdateError::FileSystem(msg) => write!(f, "文件系统错误: {}", msg),
33 UpdateError::Permission(msg) => write!(f, "权限错误: {}", msg),
34 UpdateError::Configuration(msg) => write!(f, "配置错误: {}", msg),
35 UpdateError::Other(msg) => write!(f, "其他错误: {}", msg),
36 UpdateError::Unknown(msg) => write!(f, "未知错误: {}", msg),
37 }
38 }
39}
40
41impl std::error::Error for UpdateError {}
42
43impl From<anyhow::Error> for UpdateError {
44 fn from(error: anyhow::Error) -> Self {
45 UpdateError::Unknown(error.to_string())
46 }
47}
48
49impl From<self_update::errors::Error> for UpdateError {
50 fn from(error: self_update::errors::Error) -> Self {
51 match error {
52 self_update::errors::Error::Network(_) => {
53 UpdateError::Network(error.to_string())
54 }
55 self_update::errors::Error::Release(_) => {
56 UpdateError::GitHub(error.to_string())
57 }
58 _ => UpdateError::Unknown(error.to_string()),
59 }
60 }
61}
62
63pub type UpdateResult<T> = Result<T, UpdateError>;