cf_resource_group_sdk/
error.rs1use thiserror::Error;
8
9#[derive(Error, Debug, Clone)]
11pub enum ResourceGroupError {
12 #[error("Resource not found: {code}")]
14 NotFound { code: String },
15
16 #[error("Resource already exists: {code}")]
18 TypeAlreadyExists { code: String },
19
20 #[error("Validation error: {message}")]
22 Validation { message: String },
23
24 #[error("Allowed parents violation: {message}")]
27 AllowedParentTypesViolation { message: String },
28
29 #[error("Active references exist: {message}")]
31 ConflictActiveReferences { message: String },
32
33 #[error("Conflict: {message}")]
35 Conflict { message: String },
36
37 #[error("Invalid parent type: {message}")]
39 InvalidParentType { message: String },
40
41 #[error("Cycle detected: {message}")]
43 CycleDetected { message: String },
44
45 #[error("Limit violation: {message}")]
47 LimitViolation { message: String },
48
49 #[error("Tenant incompatibility: {message}")]
58 TenantIncompatibility { message: String },
59
60 #[error("Service unavailable: {message}")]
62 ServiceUnavailable { message: String },
63
64 #[error("Access denied")]
66 AccessDenied,
67
68 #[error("Internal error")]
70 Internal,
71}
72
73impl ResourceGroupError {
74 pub fn not_found(code: impl Into<String>) -> Self {
76 Self::NotFound { code: code.into() }
77 }
78
79 pub fn type_already_exists(code: impl Into<String>) -> Self {
81 Self::TypeAlreadyExists { code: code.into() }
82 }
83
84 pub fn validation(message: impl Into<String>) -> Self {
86 Self::Validation {
87 message: message.into(),
88 }
89 }
90
91 pub fn allowed_parent_types_violation(message: impl Into<String>) -> Self {
93 Self::AllowedParentTypesViolation {
94 message: message.into(),
95 }
96 }
97
98 pub fn conflict_active_references(message: impl Into<String>) -> Self {
100 Self::ConflictActiveReferences {
101 message: message.into(),
102 }
103 }
104
105 pub fn conflict(message: impl Into<String>) -> Self {
107 Self::Conflict {
108 message: message.into(),
109 }
110 }
111
112 pub fn invalid_parent_type(message: impl Into<String>) -> Self {
114 Self::InvalidParentType {
115 message: message.into(),
116 }
117 }
118
119 pub fn cycle_detected(message: impl Into<String>) -> Self {
121 Self::CycleDetected {
122 message: message.into(),
123 }
124 }
125
126 pub fn limit_violation(message: impl Into<String>) -> Self {
128 Self::LimitViolation {
129 message: message.into(),
130 }
131 }
132
133 pub fn tenant_incompatibility(message: impl Into<String>) -> Self {
135 Self::TenantIncompatibility {
136 message: message.into(),
137 }
138 }
139
140 pub fn service_unavailable(message: impl Into<String>) -> Self {
142 Self::ServiceUnavailable {
143 message: message.into(),
144 }
145 }
146
147 #[must_use]
149 pub fn access_denied() -> Self {
150 Self::AccessDenied
151 }
152
153 #[must_use]
155 pub fn internal() -> Self {
156 Self::Internal
157 }
158}