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

🌱 (chore): Enable wrapcheck linter #4721

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kersten
Copy link
Contributor

@kersten kersten commented Mar 31, 2025

🌱 Enable wrapcheck linter

This change improves code quality by enforcing two new linting rule:

  • wrapcheck ensures wrapped errors are properly handled and not silently ignored.

The motivation is to promote modern Go practices and ensure consistent error wrapping and checking across the codebase.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 31, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @kersten. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 31, 2025
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

Hi @kersten

Thanks a lot for this PR — enabling linters like depguard and wrapcheck is a great step toward improving overall code quality and consistency 🙌

That said, regarding depguard specifically for github.com/pkg/errors:
This package is currently brought in indirectly by several upstream dependencies, including controller-runtime, client-go, and other Kubernetes-related libraries, as shown by:

go mod graph | grep github.com/pkg/errors
sigs.k8s.io/kubebuilder/testdata/project-v4 github.com/pkg/[email protected]
github.com/cert-manager/[email protected] github.com/pkg/[email protected]
gomodules.xyz/jsonpatch/[email protected] github.com/pkg/[email protected]
k8s.io/[email protected] github.com/pkg/[email protected]
k8s.io/[email protected] github.com/pkg/[email protected]
k8s.io/[email protected] github.com/pkg/[email protected]
k8s.io/[email protected] github.com/pkg/[email protected]
k8s.io/[email protected] github.com/pkg/[email protected]
sigs.k8s.io/[email protected] github.com/pkg/[email protected]
sigs.k8s.io/[email protected] github.com/pkg/[email protected]

Because of that, adding depguard with a deny rule for github.com/pkg/errors might not be very effective right now — it could lead to confusion or unnecessary friction, especially since we're not using it directly in our own codebase.

It might make more sense to enforce this rule only once those upstream dependencies have fully transitioned to the standard errors package, if that’s indeed their intended direction. (If you believe that’s the case, I’d recommend opening issues in the relevant upstream projects that are still using it.)

The addition of wrapcheck, however, shows make sense.

Thanks again for driving quality improvements like this! 💚

@kersten
Copy link
Contributor Author

kersten commented Mar 31, 2025

@camilamacedo86 Sounds good, I’ll remove the deny rule.

If we decide to go with wrapcheck, it would be great to keep an eye on PRs that introduce wrapped errors - just to make sure they don’t unintentionally use the previously mentioned package. It’s easy for someone to copy-paste code quickly, and not everyone is familiar with fmt.Errorf.

When they see linter messages like “please wrap the error,” they might end up googling and using something like errors.Wrap(err, "message") by mistake :)

@kersten kersten force-pushed the chore/lint-depguard-wrapcheck branch from 4ab98fc to 6111cf9 Compare March 31, 2025 17:14
@kersten kersten requested a review from camilamacedo86 March 31, 2025 17:14
camilamacedo86

This comment was marked as outdated.

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 31, 2025
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 31, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: camilamacedo86, kersten

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 31, 2025
@camilamacedo86 camilamacedo86 changed the title 🌱 (chore): enforce usage of stdlib errors and enable wrapcheck via golangci-lint 🌱 (chore): Enable depguard and wrapcheck linters Mar 31, 2025
@camilamacedo86 camilamacedo86 removed lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Mar 31, 2025
@camilamacedo86
Copy link
Member

camilamacedo86 commented Mar 31, 2025

Hi @kersten 👋

If we enable these linters, we'll need to update the codebase to ensure everything passes — see the failing job here:
https://github.com/kubernetes-sigs/kubebuilder/actions/runs/14177346899/job/39715844116?pr=4721

Also, it's worth noting that many of the failures appear to be false positives, or at least cases where the current code seems intentional and correct.

While linters are great tools for maintaining consistency and catching real issues, we also need to weigh their practical impact.
If a linter generates too many non-actionable or misleading errors, it can become more of a hurdle than a help — making it harder to contribute without adding real value.

So before moving forward, I think it’s worth asking:
Do we really want this linter, with this configuration?

Thanks again for looking into ways to improve the project! 🙏

@kersten kersten force-pushed the chore/lint-depguard-wrapcheck branch from 6111cf9 to 94574d6 Compare March 31, 2025 17:38
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 31, 2025
@kersten kersten changed the title 🌱 (chore): Enable depguard and wrapcheck linters 🌱 (chore): Enable wrapcheck linter Mar 31, 2025
@kersten
Copy link
Contributor Author

kersten commented Mar 31, 2025

Do we really want this linter, with this configuration?

Fair enough, I firstly removed depguard anyways because of much noise. But as I understood, wrapcheck is ok for you? I think it would make sense to enable this one, to have a better control of errors, and where they come from.

@camilamacedo86 camilamacedo86 dismissed their stale review March 31, 2025 20:37

based on the comment above

@kersten kersten force-pushed the chore/lint-depguard-wrapcheck branch 2 times, most recently from 0f21003 to c527b03 Compare April 3, 2025 07:15
@camilamacedo86
Copy link
Member

Hi @kersten

Fair enough, I firstly removed depguard anyways because of much noise. But as I understood, wrapcheck is ok for you? I think it would make sense to enable this one, to have a better control of errors, and where they come from.

That is fine.
If we pass the CI check with this one, I am OK with getting this merged.
No problem at all.

@camilamacedo86 camilamacedo86 reopened this Apr 7, 2025
@kersten kersten force-pushed the chore/lint-depguard-wrapcheck branch from c527b03 to cd0a1ab Compare April 8, 2025 11:14
@kersten kersten force-pushed the chore/lint-depguard-wrapcheck branch from cd0a1ab to 83be525 Compare April 9, 2025 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants