1use thiserror::Error;
4
5#[derive(Error, Debug)]
7pub enum KubernetesError {
8 #[error("Kubernetes API error: {0}")]
10 ApiError(#[from] kube::Error),
11
12 #[error("Configuration error: {0}")]
14 ConfigError(String),
15
16 #[error("Resource not found: {0}")]
18 ResourceNotFound(String),
19
20 #[error("Invalid resource name or pattern: {0}")]
22 InvalidResourceName(String),
23
24 #[error("Regular expression error: {0}")]
26 RegexError(#[from] regex::Error),
27
28 #[error("Serialization error: {0}")]
30 SerializationError(#[from] serde_json::Error),
31
32 #[error("YAML error: {0}")]
34 YamlError(#[from] serde_yaml::Error),
35
36 #[error("Operation failed: {0}")]
38 OperationError(String),
39
40 #[error("Namespace error: {0}")]
42 NamespaceError(String),
43
44 #[error("Permission denied: {0}")]
46 PermissionDenied(String),
47
48 #[error("Operation timed out: {0}")]
50 Timeout(String),
51
52 #[error("Generic error: {0}")]
54 Generic(#[from] anyhow::Error),
55}
56
57impl KubernetesError {
58 pub fn config_error(msg: impl Into<String>) -> Self {
60 Self::ConfigError(msg.into())
61 }
62
63 pub fn operation_error(msg: impl Into<String>) -> Self {
65 Self::OperationError(msg.into())
66 }
67
68 pub fn namespace_error(msg: impl Into<String>) -> Self {
70 Self::NamespaceError(msg.into())
71 }
72
73 pub fn permission_denied(msg: impl Into<String>) -> Self {
75 Self::PermissionDenied(msg.into())
76 }
77
78 pub fn timeout(msg: impl Into<String>) -> Self {
80 Self::Timeout(msg.into())
81 }
82}
83
84pub type KubernetesResult<T> = Result<T, KubernetesError>;