gh_labeler/
error.rs

1//! Error Handling
2//!
3//! Error type definitions used in gh-labeler
4
5use thiserror::Error;
6
7pub type Result<T> = std::result::Result<T, Error>;
8
9/// Error types for gh-labeler
10#[derive(Error, Debug)]
11pub enum Error {
12    #[error("GitHub API error: {0}")]
13    GitHubApi(#[from] octocrab::Error),
14
15    #[error("HTTP request error: {0}")]
16    Http(#[from] reqwest::Error),
17
18    #[error("JSON serialization error: {0}")]
19    Json(#[from] serde_json::Error),
20
21    #[error("YAML parsing error: {0}")]
22    Yaml(#[from] serde_yaml::Error),
23
24    #[error("Configuration validation error: {0}")]
25    ConfigValidation(String),
26
27    #[error("Label validation error: {0}")]
28    LabelValidation(String),
29
30    #[error("Repository not found: {0}")]
31    RepositoryNotFound(String),
32
33    #[error("Authentication failed: invalid token")]
34    AuthenticationFailed,
35
36    #[error("Rate limit exceeded. Please wait and try again")]
37    RateLimitExceeded,
38
39    #[error("Network error: {0}")]
40    Network(String),
41
42    #[error("IO error: {0}")]
43    Io(#[from] std::io::Error),
44
45    #[error("Invalid repository format: {0} (expected 'owner/repo')")]
46    InvalidRepositoryFormat(String),
47
48    #[error("Invalid label color: {0} (expected 6-digit hex without #)")]
49    InvalidLabelColor(String),
50
51    #[error("Generic error: {0}")]
52    Generic(String),
53}
54
55impl Error {
56    /// Create a new configuration validation error
57    pub fn config_validation<S: Into<String>>(message: S) -> Self {
58        Error::ConfigValidation(message.into())
59    }
60
61    /// Create a new label validation error  
62    pub fn label_validation<S: Into<String>>(message: S) -> Self {
63        Error::LabelValidation(message.into())
64    }
65
66    /// Create a new network error
67    pub fn network<S: Into<String>>(message: S) -> Self {
68        Error::Network(message.into())
69    }
70
71    /// Create a new generic error
72    pub fn generic<S: Into<String>>(message: S) -> Self {
73        Error::Generic(message.into())
74    }
75}