-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Improve error reporting, add errorlint, fix its warnings; drop pkg/errors #3011
Conversation
13bcbba
to
34cbc22
Compare
Hmm, weird failure in |
Rebased; set milestone to 1.1 |
Added commits that switch from |
59d43b0
to
d8de1a7
Compare
Rebased on top of merged #3024 |
An errror from ioutil.WriteFile already contains file name, so there is no need to duplicate that information. Signed-off-by: Kir Kolyshkin <[email protected]>
Working on addressing my own review comments :) |
Errors returned by unix are bare. In some cases it's impossible to find out what went wrong because there's is not enough context. Add a mountError type (mostly copy-pasted from github.com/moby/sys/mount), and mount/unmount helpers. Use these where appropriate, and convert error checks to use errors.Is. Signed-off-by: Kir Kolyshkin <[email protected]>
Errors from os.Open, os.Symlink etc do not need to be wrapped, as they are already wrapped into os.PathError. Error from unix are bare errnos and need to be wrapped. Same os.PathError is a good candidate. Signed-off-by: Kir Kolyshkin <[email protected]>
This should result in no change when the error is printed, but make the errors returned unwrappable, meaning errors.As and errors.Is will work. Signed-off-by: Kir Kolyshkin <[email protected]>
This one is tough as errorlint insists on using errors.Is, and the latter is known to not work for Go 1.13 which we still support. So, add a nolint annotation to suppress the warning, and a TODO to address it later. For intelrdt, we can do the same, but it is easier to reuse the very same function from fscommon (note we can't use fscommon for other stuff as it expects cgroupfs). Signed-off-by: Kir Kolyshkin <[email protected]>
Use fmt.Errorf with %w instead. Convert the users to the new wrapping. This fixes an errorlint warning. Signed-off-by: Kir Kolyshkin <[email protected]>
Instead of using errors.Wrap, use fmt.Errorf with %w for error wrapping. Also, use errors.Is instead of direct error comparison. Signed-off-by: Kir Kolyshkin <[email protected]>
Do this for all errors except one from unix.*. This fixes a bunch of errorlint warnings, like these libcontainer/generic_error.go:25:15: type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint) if le, ok := err.(Error); ok { ^ libcontainer/factory_linux_test.go:145:14: type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint) lerr, ok := err.(Error) ^ libcontainer/state_linux_test.go:28:11: type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint) _, ok := err.(*stateTransitionError) ^ libcontainer/seccomp/patchbpf/enosys_linux.go:88:4: switch on an error will fail on wrapped errors. Use errors.Is to check for specific errors (errorlint) switch err { ^ Signed-off-by: Kir Kolyshkin <[email protected]>
Errors from unix.* are always bare and thus can be used directly. Add //nolint:errorlint annotation to ignore errors such as these: libcontainer/system/xattrs_linux.go:18:7: comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint) case errno == unix.ERANGE: ^ libcontainer/container_linux.go:1259:9: comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint) if e != unix.EINVAL { ^ libcontainer/rootfs_linux.go:919:7: comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint) if err != unix.EINVAL && err != unix.EPERM { ^ libcontainer/rootfs_linux.go:1002:4: switch on an error will fail on wrapped errors. Use errors.Is to check for specific errors (errorlint) switch err { ^ Signed-off-by: Kir Kolyshkin <[email protected]>
Signed-off-by: Kir Kolyshkin <[email protected]>
Use Go native errors wrapping. Introduce wrapErr helper to minimise the patch size. Signed-off-by: Kir Kolyshkin <[email protected]>
Signed-off-by: Kir Kolyshkin <[email protected]>
Signed-off-by: Kir Kolyshkin <[email protected]>
Signed-off-by: Kir Kolyshkin <[email protected]>
(my own) review comments addressed; no longer WIP. |
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.
One nit, two things need changing, and one question.
Sorry, what was the question? I can't find it. |
@kolyshkin It was about removing genericError but after posting it I noticed that there was a separate PR for that. #3011 (comment) |
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, my suggestions missed that the pids.max
handling already existed in the fscommon utilities.
This commit does a few things related to error reporting and handling.
Fix and improve a bunch of error messages and associated error handling,
using features that appear in Go 1.13 (
fmt.Errorf
with%w
to wrap errors,errors.Is
anderrors.As
for unwrapping) and some other methods(such as using
os.PathError
, introducing and usingParseError
etc.)Fix all
errorlint
linter warnings, enable errorlint it in CI.Remove all uses of pkg/errors, switching to native Go error (un)wrapping.
TODO (not in this PR, as it's already too big):libcontainer/error
(done in libcontainer: rm own error system #3033)