-
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
libcontainer: rm own error system #3033
Conversation
e6fb240
to
35d2615
Compare
CI failure is probably a flake (#3035); CI restarted |
It is not used since commit 244c9fc. Signed-off-by: Kir Kolyshkin <[email protected]>
Rebased on top of #3011 |
With removal of generic_error.go, probably remove |
@@ -74,71 +74,39 @@ type BaseContainer interface { | |||
ID() string | |||
|
|||
// Returns the current status of the container. | |||
// |
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.
This documentation (about which errors can be returned) is removed because
- libcontainer/error.go already list possible errors;
- it's not easy to keep these lists up to date.
This removes libcontainer's own error wrapping system, consisting of a few types and functions, aimed at typization, wrapping and unwrapping of errors, as well as saving error stack traces. Since Go 1.13 now provides its own error wrapping mechanism and a few related functions, it makes sense to switch to it. While doing that, improve some error messages so that they start with "error", "unable to", or "can't". A few things that are worth mentioning: 1. We lose stack traces (which were never shown anyway). 2. Users of libcontainer that relied on particular errors (like ContainerNotExists) need to switch to using errors.Is with the new errors defined in error.go. 3. encoding/json is unable to unmarshal the built-in error type, so we have to introduce initError and wrap the errors into it (basically passing the error as a string). This is the same as it was before, just a tad simpler (actually the initError is a type that got removed in commit afa8443; also suddenly ierr variable name makes sense now). Signed-off-by: Kir Kolyshkin <[email protected]>
This removes the libcontainer/stacktrace package, which, as of previous commit, is no longer used. Signed-off-by: Kir Kolyshkin <[email protected]>
Thanks, @zhsj! Removed. |
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. Let's merge this before #3049 so you don't need to rebase this one.
} | ||
if err := l.validateID(id); err != nil { | ||
return nil, err | ||
} | ||
if err := l.Validator.Validate(config); err != nil { | ||
return nil, newGenericError(err, ConfigInvalid) | ||
return nil, &ConfigError{err.Error()} |
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.
Can we use %w here too?
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.
Yeah, this looks a tad weird. I might change this to using an error later.
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.
Please see #3056
@@ -249,28 +251,28 @@ type LinuxFactory struct { | |||
|
|||
func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, error) { | |||
if l.Root == "" { | |||
return nil, newGenericError(errors.New("invalid root"), ConfigInvalid) | |||
return nil, &ConfigError{"invalid root"} |
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.
Do we need &ConfigError{}
?
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.
It's a replacement for "ConfigInvalid" error code, so a caller can distinguish configuration errors from everything else.
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.
You're right @AkihiroSuda, it's better not to have it, but I was not able to come with a good solution before. Now I am; please see #3056
This removes libcontainer's own error wrapping system, consisting of a
few types and functions, aimed at typization, wrapping and unwrapping
of errors, as well as saving error stack traces.
Since Go 1.13 now provides its own error wrapping mechanism and a few
related functions, it makes sense to switch to it.
A few things worth mentioning:
We lose stack traces (which were never shown anyway).
Users of libcontainer that relied on particular errors (like
ContainerNotExists
) need to switch to usingerrors.Is
withthe new errors defined in libcontainer/error.go.
An example of such conversion:
encoding/json
is unable to unmarshal the built-inerror type, so we have to introduce
initError
and wrap the errors into it(basically passing the error as a string). This is the same
as it was before, just a tad simpler (actually the
initError
itself is a type that got removed in commit afa8443; also suddenly
ierr
variable name makes sense now).Proposed changelog entry
libcontainer.Error
type, together with error codes, is removed in favor of new errors. Users relying on removed types and codes should adopt to useerrors.Is
with new errors (seelibcontainer/errors.go
). (libcontainer: rm own error system #3033)