Skip to content

Commit 77e69f1

Browse files
Add ResourceTypeNotSupported to list of skipped error codes (#4451)
1 parent 6d66802 commit 77e69f1

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

v2/cmd/asoctl/pkg/importresources/importable_arm_resource.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/Azure/azure-service-operator/v2/internal/controllers"
2828
"github.com/Azure/azure-service-operator/v2/internal/genericarmclient"
2929
"github.com/Azure/azure-service-operator/v2/internal/reflecthelpers"
30+
"github.com/Azure/azure-service-operator/v2/internal/set"
3031
"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
3132
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/extensions"
3233
)
@@ -357,6 +358,16 @@ func (i *importableARMResource) importChildResources(
357358
return subResources, nil
358359
}
359360

361+
// skipCodes is a set of error codes that we can safely skip when importing resources.
362+
// These error codes represent cases where the request we've made doesn't make sense,
363+
// so there's no point in alerting the user to the details.
364+
var skipCodes = set.Make(
365+
"RequestUrlInvalid",
366+
"ValidationFailed",
367+
"NoRegisteredProviderFound",
368+
"ResourceTypeNotSupported",
369+
)
370+
360371
func (*importableARMResource) classifyError(err error) (string, bool) {
361372
var responseError *azcore.ResponseError
362373
if errors.As(err, &responseError) {
@@ -371,10 +382,8 @@ func (*importableARMResource) classifyError(err error) (string, bool) {
371382
}
372383

373384
if responseError.StatusCode == http.StatusBadRequest {
374-
if strings.Contains(responseError.Error(), "RequestUrlInvalid") ||
375-
strings.Contains(responseError.Error(), "ValidationFailed") ||
376-
strings.Contains(responseError.Error(), "NoRegisteredProviderFound") {
377-
// We constructed an invalid URL
385+
if skipCodes.Contains(responseError.ErrorCode) {
386+
// We made a request for something that doesn't exist, or is otherwise invalid
378387
// (Seems that some extension resources aren't permitted on some resource types)
379388
// An empty error is special cased as a silent skip, so we don't alarm casual users
380389
return "", true

0 commit comments

Comments
 (0)