Skip to main content

client_core/
error.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum DuckError {
5    #[error("Configuration parse error: {0}")]
6    Config(#[from] toml::de::Error),
7
8    #[error("DuckDB error: {0}")]
9    DuckDb(String),
10
11    #[error("HTTP error: {0}")]
12    Http(#[from] reqwest::Error),
13
14    #[error("I/O error: {0}")]
15    Io(#[from] std::io::Error),
16
17    #[error("UUID error: {0}")]
18    Uuid(#[from] uuid::Error),
19
20    #[error("Serialization error: {0}")]
21    Serde(#[from] serde_json::Error),
22
23    #[error("Task join error: {0}")]
24    Join(#[from] tokio::task::JoinError),
25
26    #[error("ZIP error: {0}")]
27    Zip(#[from] zip::result::ZipError),
28
29    #[error("Directory walk error: {0}")]
30    WalkDir(#[from] walkdir::Error),
31
32    #[error("Path strip-prefix error: {0}")]
33    StripPrefix(#[from] std::path::StripPrefixError),
34
35    #[error("Template error: {0}")]
36    Template(String),
37
38    #[error("Docker error: {0}")]
39    Docker(String),
40
41    #[error("Backup error: {0}")]
42    Backup(String),
43
44    #[error("Upgrade error: {0}")]
45    Upgrade(String),
46
47    #[error("Client is not registered")]
48    ClientNotRegistered,
49
50    #[error("Invalid response: {0}")]
51    InvalidResponse(String),
52
53    #[error("Custom error: {0}")]
54    Custom(String),
55
56    #[error("Configuration file not found")]
57    ConfigNotFound,
58
59    #[error("API error: {0}")]
60    Api(String),
61
62    #[error("Docker service error: {0}")]
63    DockerService(String),
64
65    #[error("Bad request: {0}")]
66    BadRequest(String),
67
68    #[error("Version parse error: {0}")]
69    VersionParse(String),
70
71    #[error("Service upgrade parse error: {0}")]
72    ServiceUpgradeParse(String),
73}
74
75// 为DuckDB错误实现From trait
76impl From<duckdb::Error> for DuckError {
77    fn from(err: duckdb::Error) -> Self {
78        DuckError::DuckDb(err.to_string())
79    }
80}
81
82#[cfg(feature = "indicatif")]
83impl From<indicatif::style::TemplateError> for DuckError {
84    fn from(err: indicatif::style::TemplateError) -> Self {
85        DuckError::Template(err.to_string())
86    }
87}
88
89impl DuckError {
90    pub fn custom(msg: impl Into<String>) -> Self {
91        Self::Custom(msg.into())
92    }
93
94    pub fn docker(msg: impl Into<String>) -> Self {
95        Self::Docker(msg.into())
96    }
97
98    pub fn backup(msg: impl Into<String>) -> Self {
99        Self::Backup(msg.into())
100    }
101
102    pub fn upgrade(msg: impl Into<String>) -> Self {
103        Self::Upgrade(msg.into())
104    }
105
106    pub fn docker_service(msg: impl Into<String>) -> Self {
107        Self::DockerService(msg.into())
108    }
109}