Skip to content
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

Merged
merged 2 commits into from
Oct 24, 2022

Conversation

czunker
Copy link
Contributor

@czunker czunker commented Oct 21, 2022

Signed-off-by: Christian Zunker [email protected]

This way, we can check for specific cases where resources weren't found.

Signed-off-by: Christian Zunker <[email protected]>
@czunker czunker force-pushed the christian/k8s_custom_not_found_err branch from 78ddfb3 to ada9fc3 Compare October 24, 2022 04:29
@czunker czunker marked this pull request as ready for review October 24, 2022 04:29
@czunker czunker changed the title WIP: 🧹 More expressive 'not found' error 🧹 Use extra Error type for 'object not found' Oct 24, 2022
@@ -15,6 +15,12 @@ import (
"k8s.io/apimachinery/pkg/runtime"
)

type K8sObjectNotFound struct{}

func (e *K8sObjectNotFound) Error() string {
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Thanks.

@@ -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{}
Copy link
Member

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?

Copy link
Contributor Author

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]>
@czunker czunker merged commit ba3309b into main Oct 24, 2022
@czunker czunker deleted the christian/k8s_custom_not_found_err branch October 24, 2022 12:07
@github-actions github-actions bot locked and limited conversation to collaborators Oct 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants