Skip to content

Commit

Permalink
🧹 Use general error when resources aren't found (#380)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Zunker <[email protected]>
  • Loading branch information
czunker authored Oct 24, 2022
1 parent ba3309b commit 13a4a7b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion resources/packs/aws/info/aws.lr.json

Large diffs are not rendered by default.

20 changes: 7 additions & 13 deletions resources/packs/k8s/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
)

type K8sResourceNotFound struct{}

func (e *K8sResourceNotFound) Error() string {
return "could not find k8s resource"
}

func k8sProvider(t providers.Instance) (k8s_provider.KubernetesProvider, error) {
at, ok := t.(k8s_provider.KubernetesProvider)
if !ok {
Expand Down Expand Up @@ -247,8 +241,8 @@ func initNamespacedResource[T K8sNamespacedObject](
}
}

// the error K8sResourceNotFound is checked by cnspec
return args, *new(T), &K8sResourceNotFound{}
// the error ResourceNotFound is checked by cnspec
return args, *new(T), &resources.ResourceNotFound{}
}

func initResource[T K8sObject](
Expand All @@ -272,7 +266,7 @@ func initResource[T K8sObject](
}
k8sResource := obj.(K8s)

resources, err := r(k8sResource)
k8sResources, err := r(k8sResource)
if err != nil {
return nil, *new(T), err
}
Expand Down Expand Up @@ -308,13 +302,13 @@ func initResource[T K8sObject](
return args, *new(T), fmt.Errorf("cannot use resource without specifying id or name")
}

for i := range resources {
entry := resources[i].(T)
for i := range k8sResources {
entry := k8sResources[i].(T)
if matchFn(entry) {
return nil, entry, nil
}
}

// the error K8sResourceNotFound is checked by cnspec
return nil, *new(T), &K8sResourceNotFound{}
// the error ResourceNotFound is checked by cnspec
return nil, *new(T), &resources.ResourceNotFound{}
}
2 changes: 1 addition & 1 deletion resources/packs/k8s/k8s.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions resources/resource.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package resources

type ResourceNotFound struct{}

func (e *ResourceNotFound) Error() string {
return "could not find resource"
}

// ResourceFactory for creating a new resource instance
type ResourceFactory func(*Runtime, *Args) (interface{}, error)

Expand Down

0 comments on commit 13a4a7b

Please sign in to comment.