-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🧹 Use extra Error type for 'object not found' #361
Conversation
This way, we can check for specific cases where resources weren't found. Signed-off-by: Christian Zunker <[email protected]>
78ddfb3
to
ada9fc3
Compare
resources/packs/k8s/common.go
Outdated
@@ -15,6 +15,12 @@ import ( | |||
"k8s.io/apimachinery/pkg/runtime" | |||
) | |||
|
|||
type K8sObjectNotFound struct{} | |||
|
|||
func (e *K8sObjectNotFound) Error() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Since we call it "k8s resource" in the log messages, shouldn't the error be called K8sResourceNotFound
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Thanks.
resources/packs/k8s/common.go
Outdated
@@ -241,7 +247,8 @@ func initNamespacedResource[T K8sNamespacedObject]( | |||
} | |||
} | |||
|
|||
return args, *new(T), fmt.Errorf("not found") | |||
// the error K8sObjectNotFound is checked by cnspec | |||
return args, *new(T), &K8sObjectNotFound{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where will the error be checked? It seems like in runtime.go
you are not returning that error type anymore but just error
. Is it intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: Christian Zunker <[email protected]>
Signed-off-by: Christian Zunker [email protected]