cascade_cli/
errors.rs

1/// Cascade Error Types
2#[derive(Debug, thiserror::Error)]
3pub enum CascadeError {
4    /// Git-related errors
5    #[error("Git error: {0}")]
6    Git(#[from] git2::Error),
7
8    /// Configuration errors
9    #[error("Configuration error: {0}")]
10    Config(String),
11
12    /// Branch management errors
13    #[error("Branch error: {0}")]
14    Branch(String),
15
16    /// Network errors
17    #[error("Network error: {0}")]
18    Network(String),
19
20    /// Authentication errors
21    #[error("Authentication error: {0}")]
22    Auth(String),
23
24    /// I/O errors
25    #[error("I/O error: {0}")]
26    Io(#[from] std::io::Error),
27
28    /// JSON serialization errors
29    #[error("JSON error: {0}")]
30    Json(#[from] serde_json::Error),
31
32    /// HTTP client errors
33    #[error("HTTP error: {0}")]
34    Http(#[from] reqwest::Error),
35
36    /// URL parsing errors
37    #[error("URL error: {0}")]
38    Url(#[from] url::ParseError),
39
40    /// Conflict resolution errors
41    #[error("Conflict error: {0}")]
42    Conflict(String),
43
44    /// Repository corruption errors
45    #[error("Repository corruption: {0}")]
46    Corruption(String),
47
48    /// Rebase operation errors
49    #[error("Rebase error: {0}")]
50    Rebase(String),
51
52    /// Missing dependency errors
53    #[error("Missing dependency: {0}")]
54    MissingDependency(String),
55
56    /// API rate limit errors
57    #[error("Rate limit exceeded: {0}")]
58    RateLimit(String),
59
60    /// Validation errors
61    #[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>;