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

Use %w to wrap errors, enable errorlint #2519

Merged
merged 3 commits into from
Aug 20, 2024
Merged

Conversation

kolyshkin
Copy link
Contributor

Based on patches from #2512, but much more conservative this time.

See individual commit descriptions for details.

@kolyshkin kolyshkin mentioned this pull request Aug 15, 2024
Copy link
Collaborator

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

Thanks!

The code changes all LGTM.

As for the linter … #2512 (review) says the linter has a 100% failure rate for me. On second check, I’m afraid that’s my mistake — without --max-same-issues -1 the output stopped at the copy.go examples, but the linter did find the other ones.

As mentioned elsewhere, in general I’m worried about signing up to maintain a detailed tuned linter configuration, but, *shrug*, let’s try this.

copy/copy.go Show resolved Hide resolved
Some code was not using it while it should (this allows a caller to
better inspect the error, if a need arises).

Note in a single case where we have two errors, we only make the
"primary" one unwrappable (by using %w), and explicitly convert the
"secondary" one to a string (which is a way to tell a code reviewer
and a linter that we don't want it to be unwrappable).

Found by errorlint linter.

Signed-off-by: Kir Kolyshkin <[email protected]>
Consolidate the [duplicated] code that handles and wraps the errors from
Close to a function, and call it twice.

Keep the code which deliberately converts an error from Close to a
string (rather than wrapping it) as we don't want those errors to be
unwrappable (those are not "primary" errors).

Signed-off-by: Kir Kolyshkin <[email protected]>
Use a minimal config to only warn about not using %w to wrap errors.

Signed-off-by: Kir Kolyshkin <[email protected]>
@kolyshkin
Copy link
Contributor Author

As mentioned elsewhere, in general I’m worried about signing up to maintain a detailed tuned linter configuration

I generally agree, the more complicated the config is the harder it is to maintain. In this case, I hope, this won't change much over time as the linter code is basically in maintenance mode for the last few years.

Nevertheless, let me know if you want me to drop the last commit.

@mtrmac mtrmac merged commit b908e5a into containers:main Aug 20, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants