modernize Go practices - error wrapping, dead code removal, and depre… - #4613
Merged
Conversation
✅ Deploy Preview for kptdocs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR modernizes several Go patterns across the codebase to improve error traceability (via proper wrapping), reduce maintenance burden (by removing dead code), and improve test hygiene and operational safety (env cleanup and HTTP timeouts).
Changes:
- Replaced string-formatting error construction with
%wwrapping in multiple packages to preserve error chains forerrors.Is/errors.As. - Removed unreachable migration helper code (
findResourceGroupInv) along with its test/fixture. - Improved reliability by using
t.Setenvin tests and replacinghttp.DefaultClientwith a timeout-configuredhttp.Client.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| thirdparty/cmdconfig/commands/cmdeval/cmdeval.go | Wraps underlying errors with %w to preserve error chains when reading/mutating Kptfiles. |
| release/formula/main.go | Uses a custom http.Client with a 60s timeout instead of http.DefaultClient. |
| pkg/lib/util/cmdutil/cmdutil.go | Wraps MkdirAll failures with %w to preserve the original error. |
| pkg/lib/util/attribution/attribution_test.go | Replaces os.Setenv + deferred cleanup with t.Setenv for safer test isolation. |
| pkg/lib/update/update.go | Wraps merge-comment processing errors with %w for better downstream classification. |
| pkg/lib/kptops/render_executor.go | Uses %w for KRM validation errors to keep unwrapping working. |
| pkg/fn/runtime/runner.go | Uses %w for input/output KRM validation errors to keep unwrapping working. |
| internal/testutil/testutil.go | Updates gotest.tools import to gotest.tools/v3 (non-deprecated module path). |
| go.mod | Switches direct dependency from deprecated gotest.tools v1 to gotest.tools/v3. |
| go.sum | Removes stale v1 gotest.tools sums and retains v3 sums. |
| commands/live/migrate/migratecmd.go | Removes dead/unreachable findResourceGroupInv helper and its now-unused import. |
| commands/live/migrate/migratecmd_test.go | Removes dead test + fixture tied to the removed migration helper. |
| api/kptfile/v1/validation.go | Wraps KRM validation errors with %w to preserve error chains with path context. |
| api/fnresult/v1/types.go | Wraps YAML parsing errors with %w and updates a doc comment to use any. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…cated APIs Signed-off-by: Aravindhan Ayyanathan <aravindhan.a@est.tech>
aravindtga
force-pushed
the
modernize-go-practices
branch
from
July 2, 2026 11:10
65610b5 to
0f39c90
Compare
aravindtga
marked this pull request as ready for review
July 2, 2026 11:15
aravindtga
requested review from
efiacor,
kispaljr,
liamfallon and
mozesl-nokia
as code owners
July 2, 2026 11:15
mozesl-nokia
approved these changes
Jul 2, 2026
liamfallon
approved these changes
Jul 2, 2026
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.
Description
What changed:
%s/%v/%qanderr.Error()patterns infmt.Errorfcalls with proper%werror wrapping (15 sites across 7 files)findResourceGroupInvfunction, its testTestKptMigrate_findResourceGroupInv, and thergInvObjtest fixtureos.Setenv/defer os.Setenvwitht.Setenvin tests for automatic cleanuphttp.DefaultClient(no timeout) with a customhttp.Clientwith 60s timeoutgotest.toolsimport from deprecated v1 (gotest.tools) togotest.tools/v3and removed the stale v1 dependencyinterface{}withanyin doc commentWhy it's needed:
%s/%vinstead of%wbreaks the error chain, makingerrors.Is/errors.Asunable to match wrapped errorsfindResourceGroupInv) is unreachable and triggers linter warningsgotest.toolsv1 is unmaintained; v3 is actively maintained and was already an indirect dependencyhttp.DefaultClienthas no timeout, risking indefinite hangs on network issuesos.Setenvin tests can leak environment changes if the test panics or fails before deferred cleanup runsHow it works:
Related Issue(s)
Type of Change
Checklist
AI Disclosure
If so, please describe how:
- Kiro to audit the codebase for outdated Go patterns, identify quick wins, and apply the mechanical fixes.