Migrate from pkg/errors to standard library and enable depguard linter#1002
Merged
Migrate from pkg/errors to standard library and enable depguard linter#1002
Conversation
3 tasks
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR migrates error wrapping from pkg/errors to the Go standard library via fmt.Errorf() with the %w verb and enforces this pattern with a new depguard linter rule.
- Replaces pkg/errors.Wrap with fmt.Errorf(...) in numerous controller files
- Removes pkg/errors import and updates go.mod accordingly
- Adds a depguard linter configuration to prevent reintroduction of pkg/errors
Reviewed Changes
Copilot reviewed 39 out of 39 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/controller/reconciler/k8s_job.go | Error wrapping updated using fmt.Errorf |
| internal/controller/reconciler/k8s_daemonset.go | Error wrapping updated using fmt.Errorf |
| internal/controller/reconciler/k8s_cronjob.go | Error wrapping updated using fmt.Errorf |
| internal/controller/reconciler/k8s_configmap.go | Error wrapping updated using fmt.Errorf |
| internal/controller/reconciler/grant.go | Error wrapping updated; note potential formatting inconsistency |
| internal/controller/reconciler/deployment.go | Error wrapping updated using fmt.Errorf |
| internal/controller/reconciler/apparmorprofile.go | Error wrapping updated using fmt.Errorf |
| internal/controller/clustercontroller/worker.go | Error wrapping updated using fmt.Errorf |
| internal/controller/clustercontroller/sconfigcontroller.go | Error wrapping updated using fmt.Errorf |
| internal/controller/clustercontroller/rest.go | Error wrapping updated using fmt.Errorf |
| internal/controller/clustercontroller/reconcile.go | Error wrapping updated using fmt.Errorf |
| internal/controller/clustercontroller/populate_job.go | Error wrapping updated using fmt.Errorf |
| internal/controller/clustercontroller/login.go | Error wrapping updated using fmt.Errorf |
| internal/controller/clustercontroller/exporter.go | Error wrapping updated using fmt.Errorf |
| internal/controller/clustercontroller/controller.go | Error wrapping updated using fmt.Errorf |
| internal/controller/clustercontroller/common.go | Error wrapping updated using fmt.Errorf |
| internal/controller/clustercontroller/benchmark.go | Error wrapping updated using fmt.Errorf |
| internal/controller/clustercontroller/accounting.go | Error wrapping updated using fmt.Errorf |
| go.mod | pkg/errors dependency removed and reordering updated |
| .golangci.yaml | depguard linter rule added to disallow pkg/errors |
Replace all usage of github.com/pkg/errors with Go's standard library error handling using fmt.Errorf() and the %w verb. - Replace ~240+ errors.Wrap() calls with fmt.Errorf() using %w verb - Remove github.com/pkg/errors imports from source files - Add depguard linter configuration to prevent future pkg/errors usage - Clean up import ordering and fix error message formatting consistency Benefits: - Reduced external dependency footprint - Future-proof with linter enforcement against regression - Better integration with Go 1.13+ error handling (errors.Is, errors.As) - Aligns with modern Go development best practices
cd7a8c7 to
717aa11
Compare
Collaborator
Author
|
Thanks for the review! ✅ Fixed the formatting inconsistency. Changes made:
The fix has been included in the squashed commit |
ChessProfessor
approved these changes
Jun 16, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace all usage of
github.com/pkg/errorswith Go's standard library error handling usingfmt.Errorf()and the%wverb, and enabledepguardlinter to prevent future usage.Part of #680. Closes #1001.
Changes Made
errors.Wrap(err, "message")withfmt.Errorf("message: %w", err)github.com/pkg/errorsimports from source filesdepguardlinter configuration to prevent futurepkg/errorsusageerrors.New()usage where appropriateBenefits
errors.Is,errors.As)Breaking Changes
None. All error wrapping semantics are preserved through the
%wverb.