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

pkg/cdi: add missing error checks in cache #183

Closed
wants to merge 1 commit into from

Conversation

marquiz
Copy link
Contributor

@marquiz marquiz commented Jan 10, 2024

Mostly retain the existing behavior of ignoring errors but using _ to make golangci-lint happy.

Mostly retain the existing behavior of ignoring errors but using '_' to
make golangci-lint happy.

Signed-off-by: Markus Lehtonen <[email protected]>
@marquiz
Copy link
Contributor Author

marquiz commented Jan 10, 2024

I was not completely confident I'm doing the right thing here. Thus draft :) As a general note I think the very common pattern here of omitting error checking is bad design. Either check it or then don't even return an error in the first place.

@elezar
Copy link
Contributor

elezar commented Jan 11, 2024

Syntactically, I think this is fine. I'll defer to @klihub for when we should actually return the errors when refreshing the cache.

@marquiz
Copy link
Contributor Author

marquiz commented Jan 11, 2024

Syntactically, I think this is fine. I'll defer to @klihub

Yeah, no syntax error 😇 ping @klihub

@@ -69,7 +69,9 @@ func NewCache(options ...Option) (*Cache, error) {
watch: &watch{},
}

WithSpecDirs(DefaultSpecDirs...)(c)
if err := WithSpecDirs(DefaultSpecDirs...)(c); err != nil {
Copy link
Contributor

@klihub klihub Jan 11, 2024

Choose a reason for hiding this comment

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

WithSpecDirs is an Option which can't fail, so this is definitely a behavior-unaltering change and as such definitely fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, ok, this lead me to submit #187 (replaces this particular change)

c.refresh()

return nil
return c.refresh()
Copy link
Contributor

Choose a reason for hiding this comment

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

TBH, off the top of my head I'm not sure if this could cause problems.

Looking at the code, maybe it would be better/simpler/cleaner to change the API so that [Rr]efresh() never returns an error. Since errors encountered during the last refresh can anyway be queried using GetErrors(), if a caller is interested in errors it can query them itself.

@elezar
Copy link
Contributor

elezar commented Jan 23, 2024

@marquiz this can be closed now, correct?

@marquiz
Copy link
Contributor Author

marquiz commented Jan 24, 2024

We agreed to not break the Cache API (return an error from Configure() even though it's always nil), so I'll close this one

@marquiz marquiz closed this Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants