-
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
libct/errors.go: remove ConfigError in favor of ErrInvalidConfig #3056
Conversation
03a117a
to
6c6cdab
Compare
ci failure in centos7 is a epel repo glitch. Will retry later. |
6c6cdab
to
3dc7e40
Compare
Draft until #3049 is merged |
OK, it looks like #3049 is not going anywhere, so I'll redo this without it. |
All the errors returned from Validate should tell about a configuration error. Some were lacking a context, so add it. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
3dc7e40
to
6f0a94d
Compare
Removed dependency on #3049, rebased, ready for review. |
Replace ConfigError type with ErrInvalidConfig variable. This is somewhat complicated, as we need to make all errors returned from config validator to be ErrInvalidConfig, while keeping them unwrappable. This is implemented by introducing a type which holds an underlying error, and adding Is method that answers that the error is ErrInvalidConfig. [v2: silence the linter] Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
6f0a94d
to
fce98c2
Compare
Can you provide more details on why it needs an
This confuses me somewhat; if the validator invalidated the config, applying / wrapping it in I feel like it should be either one of the above; don't wrap the error in an Looking at how it's used; runc/libcontainer/factory_linux.go Lines 259 to 261 in e918d02
Line 246 in e918d02
Lines 413 to 416 in e918d02
|
So, we want to have some predefined errors returned by libcontainer. Those are listed in libcontainer/error.go. PR #3033 did a good job of dismantling the libcontainer's own error system (in favor of Go 1.13+ errors), while keeping these predefined errors (see PR description). So, a libcontainer user can check for a particular error using errors.Is, for example: if errors.Is(err, libcontainer.ErrNotExist) One thing, though, where the above PR falls short, is "invalid config" error. There used to be This PR is solving this problem, so you can now use
Wrapping it in The "keeping then unwrappable" part means that you can still get the exact underlying error.
This PR removes
|
Right, so question is: is it needed? Looking at the code in this repository, the only relevant error that's checked is Line 58 in 5547b57
Which is not on "create", but on "delete" (container already gone situation). Outside of runc itself, it also looks to be the only error that some users check for (but using the "old" errors); https://grep.app/search?q=libcontainer.E Mostly wondering; are there practical situations where the caller can implement logic to handle these errors, other than "it's invalid"? |
@thaJeztah I don't know if anyone needs it. I did it mostly to not lose any functionality compared to what we had before #3033, and generally thinking it's good to have more structured errors. If that's not needed, I can simplify the whole thing, removing both @AkihiroSuda WDYT? |
Bit on the fence if errors should be wrapped multiple times. I think that's what Happy to hear others input though. |
I don't quite understand this. Can you share a link or something? Wrapping an error, in many cases, means adding more context to it. For example, In case of this PR, though, we wrap the error into a newly introduced type for the sole reason of making But I totally don't understand how wrapping an error means handling it. |
Here's the alternative: #3176 |
PTAL @thaJeztah (comments above) |
Closing in favor of #3176 which is simpler. |
Inspired by #3033 (comment).
Replace
ConfigError
type (introduced in #3033) with anErrInvalidConfig
variable, for better and more uniform errors returned by libcontainer.
This is somewhat complicated, as we need to make all errors returned
from config validator to be
ErrInvalidConfig
, while keeping themunwrappable.
Implemented by introducing a type which holds an underlying error,
and has the
Is
method that answers that the error isErrInvalidConfig
.