Fix more errorlint warnings. Use errors.As and errors.Is for error handling.#31667
Fix more errorlint warnings. Use errors.As and errors.Is for error handling.#31667atombrella wants to merge 3 commits intohelm:mainfrom
errors.As and errors.Is for error handling.#31667Conversation
errors.As and errors.Is for error handling.
b16ab16 to
711204d
Compare
6ec8cd9 to
711204d
Compare
6ded2ff to
e597f7f
Compare
There was a problem hiding this comment.
Changes look good. Thanks!
These large refactor PRs, while valid, can be difficult to merge due to coordinating two maintainers before a conflict arises.
Can you please fix the conflicts, and I can re-approve. And hopefully another maintainer before a conflict arises.
@gjenkins8 @TerryHowe Sure. I have fixed the merge-conflicts. |
There was a problem hiding this comment.
Pull request overview
This pull request improves error handling across the Helm codebase by adopting modern Go error handling patterns. It replaces direct error comparisons with errors.Is, type assertions with errors.As, and uses %w instead of %v in fmt.Errorf to properly wrap errors.
Changes:
- Replaced direct error comparisons (
err == specificError) witherrors.Is(err, specificError)for better wrapped error support - Replaced type assertions (
err.(*Type)) witherrors.As(err, &variable)for safer type checking - Changed error formatting from
%vto%winfmt.Errorfcalls to preserve error chains - Grouped related constants in engine.go for better code organization
Reviewed changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/strvals/parser.go | Updated io.EOF comparisons to use errors.Is |
| pkg/strvals/literal_parser.go | Updated io.EOF comparisons to use errors.Is (contains critical bugs) |
| pkg/storage/driver/sql_test.go | Changed ErrReleaseNotFound comparison to errors.Is |
| pkg/storage/driver/sql.go | Updated error wrapping to use %w format |
| pkg/storage/driver/secrets_test.go | Changed ErrReleaseNotFound comparisons to errors.Is |
| pkg/storage/driver/cfgmaps_test.go | Changed ErrReleaseNotFound comparisons to errors.Is |
| pkg/registry/transport.go | Updated io.EOF comparison to use errors.Is |
| pkg/kube/wait.go | Replaced StatusError type assertion with errors.As |
| pkg/kube/client.go | Updated error comparisons and type assertions to use errors.Is and errors.As |
| pkg/engine/engine.go | Grouped constants and updated error wrapping to use %w |
| pkg/downloader/manager.go | Updated error wrapping to use %w format |
| pkg/downloader/chart_downloader_test.go | Changed ErrNoOwnerRepo comparison to errors.Is |
| pkg/downloader/chart_downloader.go | Changed ErrNoOwnerRepo comparison to errors.Is |
| pkg/cmd/upgrade.go | Changed ErrReleaseNotFound comparison to errors.Is |
| pkg/cmd/template.go | Updated error wrapping to use %w format |
| pkg/cmd/search_repo.go | Updated error wrapping to use %w format |
| pkg/cmd/search_hub.go | Updated error wrapping to use %w format |
| pkg/cmd/rollback.go | Updated error wrapping to use %w format |
| pkg/cmd/load_plugins.go | Replaced InvokeExecError type assertion with errors.As |
| pkg/cmd/lint.go | Updated error wrapping to use %w format |
| pkg/cmd/dependency_build.go | Replaced ErrRepoNotFound type assertion with errors.As |
| pkg/chart/loader/archive/archive.go | Updated io.EOF comparison and error wrapping |
| pkg/action/validate.go | Updated error wrapping to use %w format |
| pkg/action/upgrade.go | Updated error wrapping to use %w format |
| pkg/action/package_test.go | Changed error comparison to errors.Is |
| pkg/action/install.go | Updated error wrapping to use %w format |
| internal/sympath/walk.go | Changed filepath.SkipDir comparisons to errors.Is |
| internal/plugin/runtime_subprocess_test.go | Replaced InvokeExecError type assertion with errors.As |
| internal/plugin/runtime_subprocess.go | Replaced exec.ExitError type assertions with errors.As |
| internal/plugin/installer/local_installer_test.go | Changed ErrPluginNotADirectory comparison to errors.Is |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@TerryHowe @gjenkins8 Can you please have another look? |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
10b2748 to
8462950
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| v, err := semver.NewVersion(ch.Metadata.Version) | ||
| if err != nil { | ||
| return fmt.Errorf("invalid version %s for dependency %s: %s", dep.Version, dep.Name, err) | ||
| return fmt.Errorf("invalid version %s for dependency %s: %w", dep.Version, dep.Name, err) |
There was a problem hiding this comment.
The error message here says the invalid version is dep.Version, but the parse that can fail is semver.NewVersion(ch.Metadata.Version). This can mislead users during troubleshooting. Consider reporting ch.Metadata.Version (or otherwise clarifying which version string failed to parse).
| return fmt.Errorf("invalid version %s for dependency %s: %w", dep.Version, dep.Name, err) | |
| return fmt.Errorf("invalid chart metadata version %s for dependency %s: %w", ch.Metadata.Version, dep.Name, err) |
There was a problem hiding this comment.
CoPilot keeps suggesting new things. I think it'd change scope a bit here?
ef0e907 to
cd99cdc
Compare
Use errors.As instead of type-casting, errors.Is for comparison and use of %w for error formatting in fmt.Errorf. The changes do not fully fix all of errorlint. I don't feel comfortable touching files under v1-3 as this may break compatibility with api users. Signed-off-by: Mads Jensen <atombrella@users.noreply.github.com>
cd99cdc to
28ffefc
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| if !u.DisableHooks { | ||
| if err := u.cfg.execHook(upgradedRelease, release.HookPreUpgrade, u.WaitStrategy, u.WaitOptions, u.Timeout, serverSideApply); err != nil { | ||
| if err := u.cfg.execHook(upgradedRelease, release.HookPreUpgrade, u.WaitStrategy, u.Timeout, serverSideApply); err != nil { |
There was a problem hiding this comment.
The function signature for execHook requires a waitOptions []kube.WaitOption parameter between waitStrategy and timeout. Line 457 is missing u.WaitOptions in the call to execHook. This should be u.cfg.execHook(upgradedRelease, release.HookPreUpgrade, u.WaitStrategy, u.WaitOptions, u.Timeout, serverSideApply) to match the correct signature.
| if err := u.cfg.execHook(upgradedRelease, release.HookPreUpgrade, u.WaitStrategy, u.Timeout, serverSideApply); err != nil { | |
| if err := u.cfg.execHook(upgradedRelease, release.HookPreUpgrade, u.WaitStrategy, u.WaitOptions, u.Timeout, serverSideApply); err != nil { |
| // pre-install hooks | ||
| if !i.DisableHooks { | ||
| if err := i.cfg.execHook(rel, release.HookPreInstall, i.WaitStrategy, i.WaitOptions, i.Timeout, i.ServerSideApply); err != nil { | ||
| if err := i.cfg.execHook(rel, release.HookPreInstall, i.WaitStrategy, i.Timeout, i.ServerSideApply); err != nil { |
There was a problem hiding this comment.
The function signature for execHook requires a waitOptions []kube.WaitOption parameter between waitStrategy and timeout. This call is missing i.WaitOptions. This should be i.cfg.execHook(rel, release.HookPreInstall, i.WaitStrategy, i.WaitOptions, i.Timeout, i.ServerSideApply) to match the correct signature shown in the post-install hook at line 551.
| if err := i.cfg.execHook(rel, release.HookPreInstall, i.WaitStrategy, i.Timeout, i.ServerSideApply); err != nil { | |
| if err := i.cfg.execHook(rel, release.HookPreInstall, i.WaitStrategy, i.WaitOptions, i.Timeout, i.ServerSideApply); err != nil { |
| if idx := strings.Index(remainder, ": executing "); idx != -1 { | ||
| templateName := remainder[:idx] | ||
| after := remainder[idx+len(": executing "):] |
There was a problem hiding this comment.
This change from strings.Cut to manual string index operations appears unrelated to the PR's stated purpose of fixing errorlint warnings. The strings.Cut function is available in Go 1.18+ and was working correctly. This refactoring increases code complexity without providing any benefit and is out of scope for this PR.
| if idx := strings.Index(remainder, ": executing "); idx != -1 { | |
| templateName := remainder[:idx] | |
| after := remainder[idx+len(": executing "):] | |
| if templateName, after, ok := strings.Cut(remainder, ": executing "); ok { |
| endLoc := strings.Index(afterAt, ">: ") | ||
| if endLoc == -1 { | ||
| return TraceableError{}, false | ||
| } | ||
| locationName := afterAt[:endLoc] | ||
| errMsg := afterAt[endLoc+len(">: "):] |
There was a problem hiding this comment.
This change from strings.Cut to manual string index operations appears unrelated to the PR's stated purpose of fixing errorlint warnings. The strings.Cut function is available in Go 1.18+ and was working correctly. This refactoring increases code complexity without providing any benefit and is out of scope for this PR.
| endLoc := strings.Index(afterAt, ">: ") | |
| if endLoc == -1 { | |
| return TraceableError{}, false | |
| } | |
| locationName := afterAt[:endLoc] | |
| errMsg := afterAt[endLoc+len(">: "):] | |
| locationName, errMsg, found := strings.Cut(afterAt, ">: ") | |
| if !found { | |
| return TraceableError{}, false | |
| } |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Mads Jensen <mje@inducks.org>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Mads Jensen <mje@inducks.org>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
pkg/action/upgrade.go:506
- The post-upgrade hook execution is using
release.HookPreUpgradehere. That changes behavior (pre-upgrade hooks would run twice and post-upgrade hooks would never run). This should userelease.HookPostUpgrade(and keep the correct argument list forexecHook).
if err := u.cfg.execHook(upgradedRelease, release.HookPostUpgrade, u.WaitStrategy, u.WaitOptions, u.Timeout, serverSideApply); err != nil {
u.reportToPerformUpgrade(c, upgradedRelease, results.Created, fmt.Errorf("post-upgrade hooks failed: %w", err))
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| if !u.DisableHooks { | ||
| if err := u.cfg.execHook(upgradedRelease, release.HookPreUpgrade, u.WaitStrategy, u.WaitOptions, u.Timeout, serverSideApply); err != nil { | ||
| if err := u.cfg.execHook(upgradedRelease, release.HookPreUpgrade, u.WaitStrategy, u.Timeout, serverSideApply); err != nil { |
| // pre-install hooks | ||
| if !i.DisableHooks { | ||
| if err := i.cfg.execHook(rel, release.HookPreInstall, i.WaitStrategy, i.WaitOptions, i.Timeout, i.ServerSideApply); err != nil { | ||
| if err := i.cfg.execHook(rel, release.HookPreInstall, i.WaitStrategy, i.Timeout, i.ServerSideApply); err != nil { |
What this PR does / why we need it:
Use
errors.Asinstead of type-casting,errors.Isfor comparison and use of%wfor error formatting infmt.Errorf. The changes do not fully fix all of errorlint. I don't feel comfortable touching files under v1-3 as this may break compatibility with API users.I have not successfully been able to change the use of
switchwith comparison of the error type. There are a few instances of this:Special notes for your reviewer:
If applicable:
docs neededlabel should be applied if so)