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: Fix linter findings for errorlint (part1) #12701

Merged
merged 3 commits into from
Feb 22, 2023
Merged

chore: Fix linter findings for errorlint (part1) #12701

merged 3 commits into from
Feb 22, 2023

Conversation

zak-pawel
Copy link
Collaborator

Address findings for errorlint - finds code that can cause problems with the error wrapping scheme introduced in Go 1.13.

It is only part of the bigger job.
After all findings in whole project are handled, we can enable errorlint linter to guard this.

Following findings in agent, cmd, config, internal, models, testutil and tools packages were fixed:

agent/agent.go:200:22                             errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
agent/agent.go:207:26                             errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
agent/agent.go:214:27                             errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
agent/agent.go:221:26                             errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
agent/agent.go:228:23                             errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
cmd/telegraf/main.go:199:36                       errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
cmd/telegraf/telegraf.go:155:20                   errorlint  comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error
cmd/telegraf/telegraf.go:156:60                   errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
config/config.go:476:47                           errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
config/config.go:487:69                           errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
config/config.go:617:62                           errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
config/config.go:635:62                           errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
config/config.go:651:53                           errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
config/config.go:729:101                          errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
config/config.go:874:69                           errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
config/config.go:880:56                           errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
config/deprecation.go:38:75                       errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
config/deprecation.go:45:82                       errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
config/deprecation.go:119:48                      errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
config/deprecation.go:151:71                      errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
config/secret.go:110:58                           errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
config/secret.go:130:56                           errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
config/secret.go:182:51                           errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
internal/content_coding.go:64:5                   errorlint  comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error
internal/content_coding.go:228:19                 errorlint  comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error
internal/content_coding.go:259:19                 errorlint  comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error
internal/http.go:138:16                           errorlint  type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors
internal/internal.go:187:20                       errorlint  type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors
internal/process/process.go:116:51                errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
internal/snmp/translate.go:138:69                 errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
models/filter.go:57:55                            errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
models/filter.go:61:55                            errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
models/filter.go:66:56                            errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
models/filter.go:70:56                            errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
models/filter.go:75:57                            errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
models/filter.go:79:57                            errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
models/filter.go:85:55                            errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
models/filter.go:91:55                            errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
testutil/container.go:66:54                       errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
testutil/container.go:76:48                       errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
testutil/container.go:84:47                       errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
testutil/container.go:113:56                      errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
testutil/file.go:81:79                            errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
testutil/file.go:107:76                           errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
tools/custom_builder/config.go:98:52              errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
tools/custom_builder/config.go:102:68             errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
tools/package_lxd_test/container.go:35:53         errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
tools/package_lxd_test/container.go:40:54         errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
tools/package_lxd_test/container.go:48:53         errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
tools/package_lxd_test/lxd.go:156:50              errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
tools/readme_config_includer/generator.go:81:63   errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
tools/readme_config_includer/generator.go:87:65   errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
tools/update_goversion/main.go:75:7               errorlint  comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error

@powersj powersj added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label Feb 17, 2023
Copy link
Contributor

@Hipska Hipska left a comment

Choose a reason for hiding this comment

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

Many thanks, it would be great if we can enable this linter, I can't recall how many times I asked to change %v to %w on PRs.

Shouldn't we also be consistent to always use : before the error? I see sometimes , is used..

cmd/telegraf/main.go Outdated Show resolved Hide resolved
config/config.go Outdated Show resolved Hide resolved
testutil/container.go Outdated Show resolved Hide resolved
@srebhan
Copy link
Member

srebhan commented Feb 22, 2023

@Hipska I would appreciate a consistent error formatting, but I think this is beyond the scope of this PR. However, additional PRs are welcome!

Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

@zak-pawel thanks for the epic effort. I'd love to see this linter enabled! However, I agree with the comments of @Hipska. Can you please fix those!?

cmd/telegraf/main.go Outdated Show resolved Hide resolved
testutil/container.go Outdated Show resolved Hide resolved
@Hipska
Copy link
Contributor

Hipska commented Feb 22, 2023

@srebhan during yesterdays maintainers meeting we agreed the uniform error messages with :, but there is no way to enforce it with linters. I think @zak-pawel would update the PRs to change all using , %w to use : %w.

Copy link
Contributor

@Hipska Hipska left a comment

Choose a reason for hiding this comment

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

Almost ;-)

testutil/container.go Show resolved Hide resolved
@telegraf-tiger
Copy link
Contributor

Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Nice. Thanks again @zak-pawel for this epic effort!

@srebhan srebhan merged commit f7949ca into influxdata:master Feb 22, 2023
powersj pushed a commit that referenced this pull request Feb 27, 2023
Co-authored-by: Pawel Zak <Pawel Zak>
(cherry picked from commit f7949ca)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants