-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Fix more errorlint warnings. Use errors.As and errors.Is for error handling.
#31667
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
base: main
Are you sure you want to change the base?
Conversation
errors.As and errors.Is for error handling.
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>
Signed-off-by: Mads Jensen <atombrella@users.noreply.github.com>
b16ab16 to
711204d
Compare
6ec8cd9 to
711204d
Compare
18e7091 to
6ded2ff
Compare
Signed-off-by: Mads Jensen <atombrella@users.noreply.github.com>
6ded2ff to
e597f7f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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>
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)