1#[derive(Debug, thiserror::Error)]
3pub enum CascadeError {
4 #[error("Git error: {0}")]
6 Git(#[from] git2::Error),
7
8 #[error("Configuration error: {0}")]
10 Config(String),
11
12 #[error("Branch error: {0}")]
14 Branch(String),
15
16 #[error("Network error: {0}")]
18 Network(String),
19
20 #[error("Authentication error: {0}")]
22 Auth(String),
23
24 #[error("I/O error: {0}")]
26 Io(#[from] std::io::Error),
27
28 #[error("JSON error: {0}")]
30 Json(#[from] serde_json::Error),
31
32 #[error("HTTP error: {0}")]
34 Http(#[from] reqwest::Error),
35
36 #[error("URL error: {0}")]
38 Url(#[from] url::ParseError),
39
40 #[error("Conflict error: {0}")]
42 Conflict(String),
43
44 #[error("Repository corruption: {0}")]
46 Corruption(String),
47
48 #[error("Rebase error: {0}")]
50 Rebase(String),
51
52 #[error("Missing dependency: {0}")]
54 MissingDependency(String),
55
56 #[error("Rate limit exceeded: {0}")]
58 RateLimit(String),
59
60 #[error("Validation error: {0}")]
62 Validation(String),
63}
64
65impl CascadeError {
66 pub fn config<S: Into<String>>(msg: S) -> Self {
67 CascadeError::Config(msg.into())
68 }
69
70 pub fn branch<S: Into<String>>(msg: S) -> Self {
71 CascadeError::Branch(msg.into())
72 }
73
74 pub fn auth<S: Into<String>>(msg: S) -> Self {
75 CascadeError::Auth(msg.into())
76 }
77
78 pub fn validation<S: Into<String>>(msg: S) -> Self {
79 CascadeError::Validation(msg.into())
80 }
81
82 pub fn parse<S: Into<String>>(msg: S) -> Self {
83 CascadeError::Validation(msg.into())
84 }
85
86 pub fn not_initialized<S: Into<String>>(msg: S) -> Self {
87 CascadeError::config(msg.into())
88 }
89
90 pub fn invalid_operation<S: Into<String>>(msg: S) -> Self {
91 CascadeError::Validation(msg.into())
92 }
93
94 pub fn conflict_resolution<S: Into<String>>(file: S, reason: S) -> Self {
95 CascadeError::Conflict(format!("{}: {}", file.into(), reason.into()))
96 }
97
98 pub fn bitbucket_api(status: u16, message: String) -> Self {
99 CascadeError::Conflict(format!("Bitbucket API error: {status} - {message}"))
100 }
101
102 pub fn bitbucket<S: Into<String>>(msg: S) -> Self {
103 CascadeError::Conflict(msg.into())
104 }
105}
106
107pub type Result<T> = std::result::Result<T, CascadeError>;