Skip to content

Commit 9e81803

Browse files
sgagniereBrian Strauch
andauthored
[CLI-1828] Show detailed error when attempting to delete a cluster with active connectors (#1363)
* Added detailed error response to CatchKafkaNotFoundError even when the HTTP status code is 403. Also added new suggestion to check for active connectors. * Modified corresponding golden files. * Missed a line in one of the golden files in previous commit * Modified the last suggestion to apply specifically to deletion * Modified CatchKafkaNotFoundError to only suggest checking for active connectors in the case of a delete request * Compact suggestion choosing Co-authored-by: Brian Strauch <bstrauch@confluent.io> * Cleaned up suggestion message * Added back missing newline * Updated resourceNotFoundErrMsg to say 'resource not found' instead of 'Forbidden' * Updated more functions in catcher.go to also return v2 error detail in case of a 403 response, and added an integration test to test CatchServiceAccountNotFoundError * Added integration test for deleting an environment that doesn't exist * un-capitalize service account error Co-authored-by: Brian Strauch <bstrauch@confluent.io> * un-capitalize environment error Co-authored-by: Brian Strauch <bstrauch@confluent.io> * Removed redundant line and updated some golden files * Error message code formatting Co-authored-by: Brian Strauch <bstrauch@confluent.io> * Update internal/pkg/errors/catcher.go * fix integration tests Co-authored-by: Brian Strauch <bstrauch@confluent.io>
1 parent fc52a88 commit 9e81803

File tree

15 files changed

+41
-18
lines changed

15 files changed

+41
-18
lines changed

internal/pkg/errors/catcher.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func CatchEnvironmentNotFoundError(err error, r *http.Response) error {
183183
}
184184

185185
if r != nil && r.StatusCode == http.StatusForbidden {
186-
return NewWrapErrorWithSuggestions(err, "Environment not found or access forbidden", EnvNotFoundSuggestions)
186+
return NewWrapErrorWithSuggestions(CatchV2ErrorDetailWithResponse(err, r), "environment not found or access forbidden", EnvNotFoundSuggestions)
187187
}
188188

189189
return CatchV2ErrorDetailWithResponse(err, r)
@@ -198,7 +198,11 @@ func CatchKafkaNotFoundError(err error, clusterId string, r *http.Response) erro
198198
}
199199

200200
if r != nil && r.StatusCode == http.StatusForbidden {
201-
return NewWrapErrorWithSuggestions(err, "Kafka cluster not found or access forbidden", ChooseRightEnvironmentSuggestions)
201+
suggestions := ChooseRightEnvironmentSuggestions
202+
if r.Request.Method == http.MethodDelete {
203+
suggestions = KafkaClusterDeletingSuggestions
204+
}
205+
return NewWrapErrorWithSuggestions(CatchV2ErrorDetailWithResponse(err, r), "Kafka cluster not found or access forbidden", suggestions)
202206
}
203207

204208
return CatchV2ErrorDetailWithResponse(err, r)
@@ -223,7 +227,7 @@ func CatchClusterConfigurationNotValidError(err error, r *http.Response) error {
223227

224228
func CatchApiKeyForbiddenAccessError(err error, operation string, r *http.Response) error {
225229
if r != nil && r.StatusCode == http.StatusForbidden || strings.Contains(err.Error(), "Unknown API key") {
226-
return NewWrapErrorWithSuggestions(err, fmt.Sprintf("error %s api key", operation), APIKeyNotFoundSuggestions)
230+
return NewWrapErrorWithSuggestions(CatchV2ErrorDetailWithResponse(err, r), fmt.Sprintf("error %s API key", operation), APIKeyNotFoundSuggestions)
227231
}
228232
return CatchV2ErrorDetailWithResponse(err, r)
229233
}
@@ -268,7 +272,7 @@ func CatchServiceAccountNotFoundError(err error, r *http.Response, serviceAccoun
268272
errorMsg := fmt.Sprintf(ServiceAccountNotFoundErrorMsg, serviceAccountId)
269273
return NewErrorWithSuggestions(errorMsg, ServiceAccountNotFoundSuggestions)
270274
case http.StatusForbidden:
271-
return NewWrapErrorWithSuggestions(err, "Service account not found or access forbidden", ServiceAccountNotFoundSuggestions)
275+
return NewWrapErrorWithSuggestions(CatchV2ErrorDetailWithResponse(err, r), "service account not found or access forbidden", ServiceAccountNotFoundSuggestions)
272276
}
273277
}
274278

internal/pkg/errors/error_message.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ const (
153153
KafkaClusterExpandingErrorMsg = "Your cluster is expanding. Please wait for that operation to complete before updating again."
154154
KafkaClusterShrinkingErrorMsg = "Your cluster is shrinking. Please wait for that operation to complete before updating again."
155155
KafkaClusterDeletingErrorMsg = "Your cluster is in the process of being deleted. Cannot initiate cluster resize."
156+
KafkaClusterDeletingSuggestions = ChooseRightEnvironmentSuggestions + "\n" +
157+
"Ensure the cluster is not associated with any active Connect clusters."
156158
ChooseRightEnvironmentSuggestions = "Ensure the cluster ID you entered is valid.\n" +
157159
"Ensure the cluster you are specifying belongs to the currently selected environment with `confluent kafka cluster list`, `confluent environment list`, and `confluent environment use`."
158160
UnknownTopicErrorMsg = `unknown topic "%s"`

test/environment_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func (s *CLITestSuite) TestEnvironment() {
1515
{args: "environment create saucayyy -o json", fixture: "environment/9.golden"},
1616
{args: "environment create saucayyy -o yaml", fixture: "environment/10.golden"},
1717
{args: "environment delete not-595", fixture: "environment/11.golden"},
18+
{args: "environment delete env-dne", fixture: "environment/12.golden", wantErrCode: 1},
1819
}
1920

2021
resetConfiguration(s.T())
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Error: error getting api key: Unknown API key UNKNOWN
1+
Error: error getting API key: resource not found: Unknown API key UNKNOWN
22

33
Suggestions:
44
Ensure the API key exists and has not been deleted, or create a new API key via `confluent api-key create`.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Error: unable to set active API key: Forbidden: Unknown API key UNKNOWN
1+
Error: unable to set active API key: resource not found: Unknown API key UNKNOWN
22

33
Suggestions:
44
If you did not create this API key with the CLI or created it on another computer, you must first store the API key and secret locally with `confluent api-key store UNKNOWN <secret>`.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Error: environment not found or access forbidden: 403 Forbidden
2+
3+
Suggestions:
4+
List available environments with `confluent environment list`.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Error: service account not found or access forbidden: resource not found: 403 Forbidden
2+
3+
Suggestions:
4+
List service accounts with `confluent service-account list`.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Error: failed to delete user "u-1": Forbidden: 403 Forbidden
1+
Error: failed to delete user "u-1": resource not found: 403 Forbidden
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Error: failed to update user "u-1": Forbidden: 403 Forbidden
1+
Error: failed to update user "u-1": resource not found: 403 Forbidden
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
Error: Kafka cluster not found or access forbidden: 403 Forbidden
1+
Error: Kafka cluster not found or access forbidden: resource not found: 403 Forbidden
22

33
Suggestions:
44
Ensure the cluster ID you entered is valid.
55
Ensure the cluster you are specifying belongs to the currently selected environment with `confluent kafka cluster list`, `confluent environment list`, and `confluent environment use`.
6+
Ensure the cluster is not associated with any active Connect clusters.

0 commit comments

Comments
 (0)