-
Notifications
You must be signed in to change notification settings - Fork 64
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
Stop using pkg/errors, switch to native golang errors, add errorlint and gofumpt #148
Merged
Conversation
This file contains 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
thaJeztah
reviewed
Jun 11, 2021
The main benefit of using pkg/errors was the ability to wrap errors. (The other benefit is saving the error traceback but I doubt any users of go-selinux rely on that). However, since Go 1.13 one can use native error wrapping and unwrapping (fmt.Errorf with %w, errors.Is and errors.As). Replace all uses of pkg/errors with stdlib. For wrapping errors, use either %w or, where appropriate, os.PathError. This change can be disruptive to users who rely on wrapped errors. They should change to using errors.Is / errors.As to unwrap to check the error type. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
10 tasks
os.IsNotExist doc says > New code should use errors.Is(err, os.ErrNotExist). Same for is.IsPermission: > New code should use errors.Is(err, os.ErrPermission). Fix accordingly. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
For errors returned from unix pkg, we choose to suppress the warnings, as unix errors are always bare. Also suppress error about direct comparison with strconv errors, as strconv errors are unwrappable in Go 1.13. Use errors.Is for the remaining case. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
gofumpt is a direct replacement of gofmt with a few extra rules that make great sense. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Instead of returning a bare errno from lgetxattr, wrap it into os.PathError to provide more context. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Wrap this into os.PathError to provide some context. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@thaJeztah PTAL |
rhatdan
approved these changes
Jun 24, 2021
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.
LGTM
@vrothberg @giuseppe PTAL |
vrothberg
reviewed
Jun 25, 2021
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.
LGTM
Merged
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.
pkg/errors
, switching to golang's native error wrapping.os.IsPermission
/os.IsNotExist
witherrors.Is