use thiserror::Error;
#[derive(Error, Debug)]
pub enum KubernetesError {
#[error("Kubernetes API error: {0}")]
ApiError(#[from] kube::Error),
#[error("Configuration error: {0}")]
ConfigError(String),
#[error("Resource not found: {0}")]
ResourceNotFound(String),
#[error("Invalid resource name or pattern: {0}")]
InvalidResourceName(String),
#[error("Regular expression error: {0}")]
RegexError(#[from] regex::Error),
#[error("Serialization error: {0}")]
SerializationError(#[from] serde_json::Error),
#[error("YAML error: {0}")]
YamlError(#[from] serde_yaml::Error),
#[error("Operation failed: {0}")]
OperationError(String),
#[error("Namespace error: {0}")]
NamespaceError(String),
#[error("Permission denied: {0}")]
PermissionDenied(String),
#[error("Operation timed out: {0}")]
Timeout(String),
#[error("Generic error: {0}")]
Generic(#[from] anyhow::Error),
}
impl KubernetesError {
pub fn config_error(msg: impl Into<String>) -> Self {
Self::ConfigError(msg.into())
}
pub fn operation_error(msg: impl Into<String>) -> Self {
Self::OperationError(msg.into())
}
pub fn namespace_error(msg: impl Into<String>) -> Self {
Self::NamespaceError(msg.into())
}
pub fn permission_denied(msg: impl Into<String>) -> Self {
Self::PermissionDenied(msg.into())
}
pub fn timeout(msg: impl Into<String>) -> Self {
Self::Timeout(msg.into())
}
}
pub type KubernetesResult<T> = Result<T, KubernetesError>;