errdefs: implement "IsXXX" utilities using containerd/errdefs #49378
errdefs: implement "IsXXX" utilities using containerd/errdefs #49378thaJeztah wants to merge 2 commits intomoby:masterfrom
Conversation
|
I have a branch to also update uses of containerd's errdefs package, but pushing this one first to verify compatibility. |
|
Hm... something is not working right here; That looks to be this error that it's not matching; moby/volume/drivers/extpoint.go Lines 63 to 69 in f88304a |
|
Yup, that's it; it fails without type driverNotFoundError string
func (e driverNotFoundError) Error() string {
return "volume driver not found: " + string(e)
}
func (driverNotFoundError) NotFound() {}
// OpErr is the error type returned by functions in the store package. It describes
// the operation, volume name, and error.
type OpErr struct {
// Err is the error that occurred during the operation.
Err error
// Op is the operation which caused the error, such as "create", or "list".
Op string
// Name is the name of the resource being requested for this op, typically the volume name or the driver name.
Name string
// Refs is the list of references associated with the resource.
Refs []string
}
// Error satisfies the built-in error interface type.
func (e *OpErr) Error() string {
if e == nil {
return "<nil>"
}
s := e.Op
if e.Name != "" {
s = s + " " + e.Name
}
s = s + ": " + e.Err.Error()
if len(e.Refs) > 0 {
s = s + " - " + "[" + strings.Join(e.Refs, ", ") + "]"
}
return s
}
// Cause returns the error the caused this error
func (e *OpErr) Cause() error {
return e.Err
}
// Unwrap returns the error the caused this error
func (e *OpErr) Unwrap() error {
return e.Err
}
func TestDriverNotFound(t *testing.T) {
err := driverNotFoundError("test")
if !IsNotFound(err) {
t.Fatalf("expected driver not found, got %T", err)
}
err2 := &OpErr{Op: "create", Name: "notexist", Err: err}
if !IsNotFound(err2) {
t.Fatalf("expected driver not found, got %T", err2)
}
}moby/vendor/github.com/containerd/errdefs/errors.go Lines 401 to 424 in f88304a |
|
Integration tests: Unit tests: This one is probably flaky; |
04f9c41 to
44fffaa
Compare
|
This one is still failing (on Windows at least; Linux is still running) That one would be hitting this code-path, but I see that any error from failing to find the container would be wrapped in an InvalidParameter; Lines 101 to 110 in e7da72a The only other thing in that code that looks possibly incorrect is that the errors returning from the volume driver are returned as-is, which could mean that it's producing a 404 if a volume isn't found; Lines 125 to 131 in e7da72a |
|
These still fail on Linux as well. I'm starting to wonder if the containerd errdefs's IsXXX functions do a "deep" search for errors, so continues unwrapping (therefore |
44fffaa to
3a6c94f
Compare
| func TestIntentionallyShadowed(t *testing.T) { | ||
| var ( | ||
| rootErr = errors.New("root error") | ||
|
|
||
| // Some code resulted in a "not found" error | ||
| notFoundErr = NotFound(rootErr) | ||
|
|
||
| // But a "not found" error should be considered a "invalid parameter", | ||
| // so it's intentionally wrapped. | ||
| actualErr = InvalidParameter(notFoundErr) | ||
| ) | ||
|
|
||
| if !IsInvalidParameter(actualErr) { | ||
| t.Errorf("expected invalid parameter error, got %T", actualErr) | ||
| } | ||
| if IsNotFound(actualErr) { | ||
| t.Errorf("not found error should've been masked by an invalid parameter error, but got %T", actualErr) | ||
| } | ||
| } |
There was a problem hiding this comment.
Confirmed; this test passes with our errdefs, but fails with containerd's implementation 🤔
Signed-off-by: Sebastiaan van Stijn <[email protected]>
This makes sure that errors originating from containerd are detected as errdefs types without converting them. Signed-off-by: Sebastiaan van Stijn <[email protected]>
This makes sure that errors originating from containerd are detected as
errdefs types without converting them.
- What I did
- How I did it
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)