From d453fe35b9b8b52d0677fe0c3cc8373f2f5d30d0 Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Thu, 11 Jan 2018 14:53:06 -0500 Subject: Move api/errdefs to errdefs Signed-off-by: Brian Goff --- api/errdefs/defs.go | 74 -------- api/errdefs/doc.go | 8 - api/errdefs/helpers.go | 240 ------------------------ api/errdefs/helpers_test.go | 132 ------------- api/errdefs/is.go | 114 ----------- api/server/httputils/errors.go | 2 +- api/server/httputils/httputils.go | 2 +- api/server/router/build/build_routes.go | 2 +- api/server/router/container/container_routes.go | 2 +- api/server/router/container/exec.go | 2 +- api/server/router/image/image_routes.go | 2 +- api/server/router/network/network_routes.go | 2 +- api/server/router/session/session_routes.go | 2 +- api/server/router/swarm/cluster_routes.go | 2 +- builder/dockerfile/builder.go | 2 +- builder/dockerfile/dispatchers.go | 2 +- builder/dockerfile/evaluator.go | 2 +- builder/remotecontext/remote.go | 2 +- daemon/archive.go | 2 +- daemon/attach.go | 2 +- daemon/cluster/controllers/plugin/controller.go | 2 +- daemon/cluster/helpers.go | 2 +- daemon/cluster/networks.go | 2 +- daemon/cluster/nodes.go | 2 +- daemon/cluster/services.go | 2 +- daemon/cluster/swarm.go | 2 +- daemon/commit.go | 2 +- daemon/container.go | 2 +- daemon/container_linux.go | 2 +- daemon/container_operations.go | 2 +- daemon/container_operations_unix.go | 2 +- daemon/create.go | 2 +- daemon/daemon.go | 2 +- daemon/daemon_test.go | 2 +- daemon/delete.go | 2 +- daemon/errors.go | 2 +- daemon/exec.go | 2 +- daemon/export.go | 2 +- daemon/graphdriver/quota/errors.go | 2 +- daemon/image.go | 2 +- daemon/image_delete.go | 2 +- daemon/image_pull.go | 2 +- daemon/import.go | 2 +- daemon/inspect.go | 2 +- daemon/kill.go | 2 +- daemon/list.go | 2 +- daemon/logs.go | 2 +- daemon/names.go | 2 +- daemon/network.go | 2 +- daemon/rename.go | 2 +- daemon/start.go | 2 +- daemon/start_unix.go | 2 +- daemon/stop.go | 2 +- daemon/update.go | 2 +- daemon/volumes.go | 2 +- distribution/errors.go | 2 +- errdefs/defs.go | 74 ++++++++ errdefs/doc.go | 8 + errdefs/helpers.go | 240 ++++++++++++++++++++++++ errdefs/helpers_test.go | 132 +++++++++++++ errdefs/is.go | 114 +++++++++++ libcontainerd/client_daemon.go | 2 +- libcontainerd/errors.go | 2 +- plugin/backend_linux.go | 2 +- plugin/executor/containerd/containerd.go | 2 +- plugin/manager_linux.go | 2 +- plugin/store.go | 2 +- registry/auth.go | 2 +- registry/errors.go | 2 +- registry/service.go | 2 +- registry/session.go | 2 +- volume/local/local.go | 2 +- 72 files changed, 630 insertions(+), 630 deletions(-) delete mode 100644 api/errdefs/defs.go delete mode 100644 api/errdefs/doc.go delete mode 100644 api/errdefs/helpers.go delete mode 100644 api/errdefs/helpers_test.go delete mode 100644 api/errdefs/is.go create mode 100644 errdefs/defs.go create mode 100644 errdefs/doc.go create mode 100644 errdefs/helpers.go create mode 100644 errdefs/helpers_test.go create mode 100644 errdefs/is.go diff --git a/api/errdefs/defs.go b/api/errdefs/defs.go deleted file mode 100644 index 29c3619600..0000000000 --- a/api/errdefs/defs.go +++ /dev/null @@ -1,74 +0,0 @@ -package errdefs - -// ErrNotFound signals that the requested object doesn't exist -type ErrNotFound interface { - NotFound() -} - -// ErrInvalidParameter signals that the user input is invalid -type ErrInvalidParameter interface { - InvalidParameter() -} - -// ErrConflict signals that some internal state conflicts with the requested action and can't be performed. -// A change in state should be able to clear this error. -type ErrConflict interface { - Conflict() -} - -// ErrUnauthorized is used to signify that the user is not authorized to perform a specific action -type ErrUnauthorized interface { - Unauthorized() -} - -// ErrUnavailable signals that the requested action/subsystem is not available. -type ErrUnavailable interface { - Unavailable() -} - -// ErrForbidden signals that the requested action cannot be performed under any circumstances. -// When a ErrForbidden is returned, the caller should never retry the action. -type ErrForbidden interface { - Forbidden() -} - -// ErrSystem signals that some internal error occurred. -// An example of this would be a failed mount request. -type ErrSystem interface { - ErrSystem() -} - -// ErrNotModified signals that an action can't be performed because it's already in the desired state -type ErrNotModified interface { - NotModified() -} - -// ErrAlreadyExists is a special case of ErrConflict which signals that the desired object already exists -type ErrAlreadyExists interface { - AlreadyExists() -} - -// ErrNotImplemented signals that the requested action/feature is not implemented on the system as configured. -type ErrNotImplemented interface { - NotImplemented() -} - -// ErrUnknown signals that the kind of error that occurred is not known. -type ErrUnknown interface { - Unknown() -} - -// ErrCancelled signals that the action was cancelled. -type ErrCancelled interface { - Cancelled() -} - -// ErrDeadline signals that the deadline was reached before the action completed. -type ErrDeadline interface { - DeadlineExceeded() -} - -// ErrDataLoss indicates that data was lost or there is data corruption. -type ErrDataLoss interface { - DataLoss() -} diff --git a/api/errdefs/doc.go b/api/errdefs/doc.go deleted file mode 100644 index 065346aa29..0000000000 --- a/api/errdefs/doc.go +++ /dev/null @@ -1,8 +0,0 @@ -// Package errdefs defines a set of error interfaces that packages should use for communicating classes of errors. -// Errors that cross the package boundary should implement one (and only one) of these interfaces. -// -// Packages should not reference these interfaces directly, only implement them. -// To check if a particular error implements one of these interfaces, there are helper -// functions provided (e.g. `Is`) which can be used rather than asserting the interfaces directly. -// If you must assert on these interfaces, be sure to check the causal chain (`err.Cause()`). -package errdefs diff --git a/api/errdefs/helpers.go b/api/errdefs/helpers.go deleted file mode 100644 index 5afa944461..0000000000 --- a/api/errdefs/helpers.go +++ /dev/null @@ -1,240 +0,0 @@ -package errdefs - -import "context" - -type errNotFound struct{ error } - -func (errNotFound) NotFound() {} - -func (e errNotFound) Cause() error { - return e.error -} - -// NotFound is a helper to create an error of the class with the same name from any error type -func NotFound(err error) error { - if err == nil { - return nil - } - return errNotFound{err} -} - -type errInvalidParameter struct{ error } - -func (errInvalidParameter) InvalidParameter() {} - -func (e errInvalidParameter) Cause() error { - return e.error -} - -// InvalidParameter is a helper to create an error of the class with the same name from any error type -func InvalidParameter(err error) error { - if err == nil { - return nil - } - return errInvalidParameter{err} -} - -type errConflict struct{ error } - -func (errConflict) Conflict() {} - -func (e errConflict) Cause() error { - return e.error -} - -// Conflict is a helper to create an error of the class with the same name from any error type -func Conflict(err error) error { - if err == nil { - return nil - } - return errConflict{err} -} - -type errUnauthorized struct{ error } - -func (errUnauthorized) Unauthorized() {} - -func (e errUnauthorized) Cause() error { - return e.error -} - -// Unauthorized is a helper to create an error of the class with the same name from any error type -func Unauthorized(err error) error { - if err == nil { - return nil - } - return errUnauthorized{err} -} - -type errUnavailable struct{ error } - -func (errUnavailable) Unavailable() {} - -func (e errUnavailable) Cause() error { - return e.error -} - -// Unavailable is a helper to create an error of the class with the same name from any error type -func Unavailable(err error) error { - return errUnavailable{err} -} - -type errForbidden struct{ error } - -func (errForbidden) Forbidden() {} - -func (e errForbidden) Cause() error { - return e.error -} - -// Forbidden is a helper to create an error of the class with the same name from any error type -func Forbidden(err error) error { - if err == nil { - return nil - } - return errForbidden{err} -} - -type errSystem struct{ error } - -func (errSystem) System() {} - -func (e errSystem) Cause() error { - return e.error -} - -// System is a helper to create an error of the class with the same name from any error type -func System(err error) error { - if err == nil { - return nil - } - return errSystem{err} -} - -type errNotModified struct{ error } - -func (errNotModified) NotModified() {} - -func (e errNotModified) Cause() error { - return e.error -} - -// NotModified is a helper to create an error of the class with the same name from any error type -func NotModified(err error) error { - if err == nil { - return nil - } - return errNotModified{err} -} - -type errAlreadyExists struct{ error } - -func (errAlreadyExists) AlreadyExists() {} - -func (e errAlreadyExists) Cause() error { - return e.error -} - -// AlreadyExists is a helper to create an error of the class with the same name from any error type -func AlreadyExists(err error) error { - if err == nil { - return nil - } - return errAlreadyExists{err} -} - -type errNotImplemented struct{ error } - -func (errNotImplemented) NotImplemented() {} - -func (e errNotImplemented) Cause() error { - return e.error -} - -// NotImplemented is a helper to create an error of the class with the same name from any error type -func NotImplemented(err error) error { - if err == nil { - return nil - } - return errNotImplemented{err} -} - -type errUnknown struct{ error } - -func (errUnknown) Unknown() {} - -func (e errUnknown) Cause() error { - return e.error -} - -// Unknown is a helper to create an error of the class with the same name from any error type -func Unknown(err error) error { - if err == nil { - return nil - } - return errUnknown{err} -} - -type errCancelled struct{ error } - -func (errCancelled) Cancelled() {} - -func (e errCancelled) Cause() error { - return e.error -} - -// Cancelled is a helper to create an error of the class with the same name from any error type -func Cancelled(err error) error { - if err == nil { - return nil - } - return errCancelled{err} -} - -type errDeadline struct{ error } - -func (errDeadline) DeadlineExceeded() {} - -func (e errDeadline) Cause() error { - return e.error -} - -// Deadline is a helper to create an error of the class with the same name from any error type -func Deadline(err error) error { - if err == nil { - return nil - } - return errDeadline{err} -} - -type errDataLoss struct{ error } - -func (errDataLoss) DataLoss() {} - -func (e errDataLoss) Cause() error { - return e.error -} - -// DataLoss is a helper to create an error of the class with the same name from any error type -func DataLoss(err error) error { - if err == nil { - return nil - } - return errDataLoss{err} -} - -// FromContext returns the error class from the passed in context -func FromContext(ctx context.Context) error { - e := ctx.Err() - if e == nil { - return nil - } - - if e == context.Canceled { - return Cancelled(e) - } - if e == context.DeadlineExceeded { - return Deadline(e) - } - return Unknown(e) -} diff --git a/api/errdefs/helpers_test.go b/api/errdefs/helpers_test.go deleted file mode 100644 index 984f0a77a9..0000000000 --- a/api/errdefs/helpers_test.go +++ /dev/null @@ -1,132 +0,0 @@ -package errdefs - -import ( - "errors" - "testing" -) - -var errTest = errors.New("this is a test") - -type causal interface { - Cause() error -} - -func TestNotFound(t *testing.T) { - e := NotFound(errTest) - if !IsNotFound(e) { - t.Fatalf("expected not found error, got: %T", e) - } - if cause := e.(causal).Cause(); cause != errTest { - t.Fatalf("causual should be errTest, got: %v", cause) - } -} - -func TestConflict(t *testing.T) { - e := Conflict(errTest) - if !IsConflict(e) { - t.Fatalf("expected conflcit error, got: %T", e) - } - if cause := e.(causal).Cause(); cause != errTest { - t.Fatalf("causual should be errTest, got: %v", cause) - } -} - -func TestForbidden(t *testing.T) { - e := Forbidden(errTest) - if !IsForbidden(e) { - t.Fatalf("expected forbidden error, got: %T", e) - } - if cause := e.(causal).Cause(); cause != errTest { - t.Fatalf("causual should be errTest, got: %v", cause) - } -} - -func TestInvalidParameter(t *testing.T) { - e := InvalidParameter(errTest) - if !IsInvalidParameter(e) { - t.Fatalf("expected invalid argument error, got %T", e) - } - if cause := e.(causal).Cause(); cause != errTest { - t.Fatalf("causual should be errTest, got: %v", cause) - } -} - -func TestNotImplemented(t *testing.T) { - e := NotImplemented(errTest) - if !IsNotImplemented(e) { - t.Fatalf("expected not implemented error, got %T", e) - } - if cause := e.(causal).Cause(); cause != errTest { - t.Fatalf("causual should be errTest, got: %v", cause) - } -} - -func TestNotModified(t *testing.T) { - e := NotModified(errTest) - if !IsNotModified(e) { - t.Fatalf("expected not modified error, got %T", e) - } - if cause := e.(causal).Cause(); cause != errTest { - t.Fatalf("causual should be errTest, got: %v", cause) - } -} - -func TestAlreadyExists(t *testing.T) { - e := AlreadyExists(errTest) - if !IsAlreadyExists(e) { - t.Fatalf("expected already exists error, got %T", e) - } - if cause := e.(causal).Cause(); cause != errTest { - t.Fatalf("causual should be errTest, got: %v", cause) - } -} - -func TestUnauthorized(t *testing.T) { - e := Unauthorized(errTest) - if !IsUnauthorized(e) { - t.Fatalf("expected unauthorized error, got %T", e) - } - if cause := e.(causal).Cause(); cause != errTest { - t.Fatalf("causual should be errTest, got: %v", cause) - } -} - -func TestUnknown(t *testing.T) { - e := Unknown(errTest) - if !IsUnknown(e) { - t.Fatalf("expected unknown error, got %T", e) - } - if cause := e.(causal).Cause(); cause != errTest { - t.Fatalf("causual should be errTest, got: %v", cause) - } -} - -func TestCancelled(t *testing.T) { - e := Cancelled(errTest) - if !IsCancelled(e) { - t.Fatalf("expected canclled error, got %T", e) - } - if cause := e.(causal).Cause(); cause != errTest { - t.Fatalf("causual should be errTest, got: %v", cause) - } -} - -func TestDeadline(t *testing.T) { - e := Deadline(errTest) - if !IsDeadline(e) { - t.Fatalf("expected deadline error, got %T", e) - } - if cause := e.(causal).Cause(); cause != errTest { - t.Fatalf("causual should be errTest, got: %v", cause) - } -} - -func TestIsDataLoss(t *testing.T) { - e := DataLoss(errTest) - if !IsDataLoss(e) { - t.Fatalf("expected data loss error, got %T", e) - } - if cause := e.(causal).Cause(); cause != errTest { - t.Fatalf("causual should be errTest, got: %v", cause) - } -} diff --git a/api/errdefs/is.go b/api/errdefs/is.go deleted file mode 100644 index 286ffd694a..0000000000 --- a/api/errdefs/is.go +++ /dev/null @@ -1,114 +0,0 @@ -package errdefs - -type causer interface { - Cause() error -} - -func getImplementer(err error) error { - switch e := err.(type) { - case - ErrNotFound, - ErrInvalidParameter, - ErrConflict, - ErrUnauthorized, - ErrUnavailable, - ErrForbidden, - ErrSystem, - ErrNotModified, - ErrAlreadyExists, - ErrNotImplemented, - ErrCancelled, - ErrDeadline, - ErrDataLoss, - ErrUnknown: - return e - case causer: - return getImplementer(e.Cause()) - default: - return err - } -} - -// IsNotFound returns if the passed in error is an ErrNotFound -func IsNotFound(err error) bool { - _, ok := getImplementer(err).(ErrNotFound) - return ok -} - -// IsInvalidParameter returns if the passed in error is an ErrInvalidParameter -func IsInvalidParameter(err error) bool { - _, ok := getImplementer(err).(ErrInvalidParameter) - return ok -} - -// IsConflict returns if the passed in error is an ErrConflict -func IsConflict(err error) bool { - _, ok := getImplementer(err).(ErrConflict) - return ok -} - -// IsUnauthorized returns if the the passed in error is an ErrUnauthorized -func IsUnauthorized(err error) bool { - _, ok := getImplementer(err).(ErrUnauthorized) - return ok -} - -// IsUnavailable returns if the passed in error is an ErrUnavailable -func IsUnavailable(err error) bool { - _, ok := getImplementer(err).(ErrUnavailable) - return ok -} - -// IsForbidden returns if the passed in error is an ErrForbidden -func IsForbidden(err error) bool { - _, ok := getImplementer(err).(ErrForbidden) - return ok -} - -// IsSystem returns if the passed in error is an ErrSystem -func IsSystem(err error) bool { - _, ok := getImplementer(err).(ErrSystem) - return ok -} - -// IsNotModified returns if the passed in error is a NotModified error -func IsNotModified(err error) bool { - _, ok := getImplementer(err).(ErrNotModified) - return ok -} - -// IsAlreadyExists returns if the passed in error is a AlreadyExists error -func IsAlreadyExists(err error) bool { - _, ok := getImplementer(err).(ErrAlreadyExists) - return ok -} - -// IsNotImplemented returns if the passed in error is an ErrNotImplemented -func IsNotImplemented(err error) bool { - _, ok := getImplementer(err).(ErrNotImplemented) - return ok -} - -// IsUnknown returns if the passed in error is an ErrUnknown -func IsUnknown(err error) bool { - _, ok := getImplementer(err).(ErrUnknown) - return ok -} - -// IsCancelled returns if the passed in error is an ErrCancelled -func IsCancelled(err error) bool { - _, ok := getImplementer(err).(ErrCancelled) - return ok -} - -// IsDeadline returns if the passed in error is an ErrDeadline -func IsDeadline(err error) bool { - _, ok := getImplementer(err).(ErrDeadline) - return ok -} - -// IsDataLoss returns if the passed in error is an ErrDataLoss -func IsDataLoss(err error) bool { - _, ok := getImplementer(err).(ErrDataLoss) - return ok -} diff --git a/api/server/httputils/errors.go b/api/server/httputils/errors.go index 577d19c166..f5008223c9 100644 --- a/api/server/httputils/errors.go +++ b/api/server/httputils/errors.go @@ -4,9 +4,9 @@ import ( "fmt" "net/http" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/versions" + "github.com/docker/docker/errdefs" "github.com/gorilla/mux" "github.com/sirupsen/logrus" "google.golang.org/grpc" diff --git a/api/server/httputils/httputils.go b/api/server/httputils/httputils.go index dbf5b7a2a0..e292928bf6 100644 --- a/api/server/httputils/httputils.go +++ b/api/server/httputils/httputils.go @@ -6,7 +6,7 @@ import ( "net/http" "strings" - "github.com/docker/docker/api/errdefs" + "github.com/docker/docker/errdefs" "github.com/pkg/errors" "github.com/sirupsen/logrus" "golang.org/x/net/context" diff --git a/api/server/router/build/build_routes.go b/api/server/router/build/build_routes.go index 553f8fcee4..491fa85a86 100644 --- a/api/server/router/build/build_routes.go +++ b/api/server/router/build/build_routes.go @@ -13,12 +13,12 @@ import ( "strings" "sync" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/server/httputils" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/backend" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/versions" + "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/pkg/progress" "github.com/docker/docker/pkg/streamformatter" diff --git a/api/server/router/container/container_routes.go b/api/server/router/container/container_routes.go index 0343072283..5f8456d706 100644 --- a/api/server/router/container/container_routes.go +++ b/api/server/router/container/container_routes.go @@ -8,7 +8,6 @@ import ( "strconv" "syscall" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/server/httputils" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/backend" @@ -16,6 +15,7 @@ import ( "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/versions" containerpkg "github.com/docker/docker/container" + "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/pkg/signal" "github.com/pkg/errors" diff --git a/api/server/router/container/exec.go b/api/server/router/container/exec.go index 60be8476eb..6dfca729c5 100644 --- a/api/server/router/container/exec.go +++ b/api/server/router/container/exec.go @@ -7,10 +7,10 @@ import ( "net/http" "strconv" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/server/httputils" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/versions" + "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/stdcopy" "github.com/sirupsen/logrus" "golang.org/x/net/context" diff --git a/api/server/router/image/image_routes.go b/api/server/router/image/image_routes.go index 42e2710828..dc16a23af0 100644 --- a/api/server/router/image/image_routes.go +++ b/api/server/router/image/image_routes.go @@ -10,12 +10,12 @@ import ( "strconv" "strings" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/server/httputils" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/backend" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/versions" + "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/pkg/streamformatter" "github.com/docker/docker/pkg/system" diff --git a/api/server/router/network/network_routes.go b/api/server/router/network/network_routes.go index eb5dfe2a4d..fcfeb83f55 100644 --- a/api/server/router/network/network_routes.go +++ b/api/server/router/network/network_routes.go @@ -8,12 +8,12 @@ import ( "golang.org/x/net/context" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/server/httputils" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/versions" + "github.com/docker/docker/errdefs" "github.com/docker/libnetwork" netconst "github.com/docker/libnetwork/datastore" "github.com/docker/libnetwork/networkdb" diff --git a/api/server/router/session/session_routes.go b/api/server/router/session/session_routes.go index 49493cdf64..8eb8074ebc 100644 --- a/api/server/router/session/session_routes.go +++ b/api/server/router/session/session_routes.go @@ -3,7 +3,7 @@ package session import ( "net/http" - "github.com/docker/docker/api/errdefs" + "github.com/docker/docker/errdefs" "golang.org/x/net/context" ) diff --git a/api/server/router/swarm/cluster_routes.go b/api/server/router/swarm/cluster_routes.go index 124900d459..bd98acfcf1 100644 --- a/api/server/router/swarm/cluster_routes.go +++ b/api/server/router/swarm/cluster_routes.go @@ -6,13 +6,13 @@ import ( "net/http" "strconv" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/server/httputils" basictypes "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/backend" "github.com/docker/docker/api/types/filters" types "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/versions" + "github.com/docker/docker/errdefs" "github.com/pkg/errors" "github.com/sirupsen/logrus" "golang.org/x/net/context" diff --git a/builder/dockerfile/builder.go b/builder/dockerfile/builder.go index bd2418f59e..0354b2d3f9 100644 --- a/builder/dockerfile/builder.go +++ b/builder/dockerfile/builder.go @@ -9,7 +9,6 @@ import ( "strings" "time" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/backend" "github.com/docker/docker/api/types/container" @@ -18,6 +17,7 @@ import ( "github.com/docker/docker/builder/dockerfile/parser" "github.com/docker/docker/builder/fscache" "github.com/docker/docker/builder/remotecontext" + "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/idtools" "github.com/docker/docker/pkg/streamformatter" "github.com/docker/docker/pkg/stringid" diff --git a/builder/dockerfile/dispatchers.go b/builder/dockerfile/dispatchers.go index f1f886007e..1cf275d8c4 100644 --- a/builder/dockerfile/dispatchers.go +++ b/builder/dockerfile/dispatchers.go @@ -15,12 +15,12 @@ import ( "strings" "github.com/docker/docker/api" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/strslice" "github.com/docker/docker/builder" "github.com/docker/docker/builder/dockerfile/instructions" "github.com/docker/docker/builder/dockerfile/parser" + "github.com/docker/docker/errdefs" "github.com/docker/docker/image" "github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/signal" diff --git a/builder/dockerfile/evaluator.go b/builder/dockerfile/evaluator.go index de9cdaa924..cf3d4fd01e 100644 --- a/builder/dockerfile/evaluator.go +++ b/builder/dockerfile/evaluator.go @@ -24,10 +24,10 @@ import ( "strconv" "strings" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types/container" "github.com/docker/docker/builder" "github.com/docker/docker/builder/dockerfile/instructions" + "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/system" "github.com/docker/docker/runconfig/opts" "github.com/pkg/errors" diff --git a/builder/remotecontext/remote.go b/builder/remotecontext/remote.go index 0c3345c785..b67914cc11 100644 --- a/builder/remotecontext/remote.go +++ b/builder/remotecontext/remote.go @@ -10,7 +10,7 @@ import ( "net/url" "regexp" - "github.com/docker/docker/api/errdefs" + "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/ioutils" "github.com/pkg/errors" ) diff --git a/daemon/archive.go b/daemon/archive.go index ddc4b572bd..69301342ef 100644 --- a/daemon/archive.go +++ b/daemon/archive.go @@ -5,9 +5,9 @@ import ( "os" "strings" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types" "github.com/docker/docker/container" + "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/chrootarchive" "github.com/docker/docker/pkg/ioutils" diff --git a/daemon/attach.go b/daemon/attach.go index 1b52fd0168..d63eaa6632 100644 --- a/daemon/attach.go +++ b/daemon/attach.go @@ -5,11 +5,11 @@ import ( "fmt" "io" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types/backend" "github.com/docker/docker/container" "github.com/docker/docker/container/stream" "github.com/docker/docker/daemon/logger" + "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/stdcopy" "github.com/docker/docker/pkg/term" "github.com/pkg/errors" diff --git a/daemon/cluster/controllers/plugin/controller.go b/daemon/cluster/controllers/plugin/controller.go index b48c9fd4e2..d4f24e82df 100644 --- a/daemon/cluster/controllers/plugin/controller.go +++ b/daemon/cluster/controllers/plugin/controller.go @@ -6,9 +6,9 @@ import ( "net/http" "github.com/docker/distribution/reference" - "github.com/docker/docker/api/errdefs" enginetypes "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm/runtime" + "github.com/docker/docker/errdefs" "github.com/docker/docker/plugin" "github.com/docker/docker/plugin/v2" "github.com/docker/swarmkit/api" diff --git a/daemon/cluster/helpers.go b/daemon/cluster/helpers.go index 52d0cd173d..9541bff390 100644 --- a/daemon/cluster/helpers.go +++ b/daemon/cluster/helpers.go @@ -3,7 +3,7 @@ package cluster import ( "fmt" - "github.com/docker/docker/api/errdefs" + "github.com/docker/docker/errdefs" swarmapi "github.com/docker/swarmkit/api" "github.com/pkg/errors" "golang.org/x/net/context" diff --git a/daemon/cluster/networks.go b/daemon/cluster/networks.go index e43808ddba..081526f768 100644 --- a/daemon/cluster/networks.go +++ b/daemon/cluster/networks.go @@ -3,11 +3,11 @@ package cluster import ( "fmt" - "github.com/docker/docker/api/errdefs" apitypes "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/network" types "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/daemon/cluster/convert" + "github.com/docker/docker/errdefs" "github.com/docker/docker/runconfig" swarmapi "github.com/docker/swarmkit/api" "github.com/pkg/errors" diff --git a/daemon/cluster/nodes.go b/daemon/cluster/nodes.go index 6a345bea0a..879d272e75 100644 --- a/daemon/cluster/nodes.go +++ b/daemon/cluster/nodes.go @@ -1,10 +1,10 @@ package cluster import ( - "github.com/docker/docker/api/errdefs" apitypes "github.com/docker/docker/api/types" types "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/daemon/cluster/convert" + "github.com/docker/docker/errdefs" swarmapi "github.com/docker/swarmkit/api" "golang.org/x/net/context" ) diff --git a/daemon/cluster/services.go b/daemon/cluster/services.go index 6d2676540e..931d17c75f 100644 --- a/daemon/cluster/services.go +++ b/daemon/cluster/services.go @@ -11,12 +11,12 @@ import ( "time" "github.com/docker/distribution/reference" - "github.com/docker/docker/api/errdefs" apitypes "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/backend" types "github.com/docker/docker/api/types/swarm" timetypes "github.com/docker/docker/api/types/time" "github.com/docker/docker/daemon/cluster/convert" + "github.com/docker/docker/errdefs" runconfigopts "github.com/docker/docker/runconfig/opts" swarmapi "github.com/docker/swarmkit/api" gogotypes "github.com/gogo/protobuf/types" diff --git a/daemon/cluster/swarm.go b/daemon/cluster/swarm.go index 4de44656d9..3c7a23b71d 100644 --- a/daemon/cluster/swarm.go +++ b/daemon/cluster/swarm.go @@ -6,11 +6,11 @@ import ( "strings" "time" - "github.com/docker/docker/api/errdefs" apitypes "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" types "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/daemon/cluster/convert" + "github.com/docker/docker/errdefs" "github.com/docker/docker/opts" "github.com/docker/docker/pkg/signal" swarmapi "github.com/docker/swarmkit/api" diff --git a/daemon/commit.go b/daemon/commit.go index 3208b17817..b2c969316b 100644 --- a/daemon/commit.go +++ b/daemon/commit.go @@ -9,11 +9,11 @@ import ( "time" "github.com/docker/distribution/reference" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types/backend" containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/builder/dockerfile" "github.com/docker/docker/container" + "github.com/docker/docker/errdefs" "github.com/docker/docker/image" "github.com/docker/docker/layer" "github.com/docker/docker/pkg/ioutils" diff --git a/daemon/container.go b/daemon/container.go index c062e7ac76..d55c98f5a7 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -9,11 +9,11 @@ import ( "strings" "time" - "github.com/docker/docker/api/errdefs" containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/strslice" "github.com/docker/docker/container" "github.com/docker/docker/daemon/network" + "github.com/docker/docker/errdefs" "github.com/docker/docker/image" "github.com/docker/docker/opts" "github.com/docker/docker/pkg/signal" diff --git a/daemon/container_linux.go b/daemon/container_linux.go index 6c9d52509f..d63f4b72a5 100644 --- a/daemon/container_linux.go +++ b/daemon/container_linux.go @@ -3,8 +3,8 @@ package daemon import ( - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/container" + "github.com/docker/docker/errdefs" ) func (daemon *Daemon) saveApparmorConfig(container *container.Container) error { diff --git a/daemon/container_operations.go b/daemon/container_operations.go index aa18f3767c..32846a2f77 100644 --- a/daemon/container_operations.go +++ b/daemon/container_operations.go @@ -10,11 +10,11 @@ import ( "strings" "time" - "github.com/docker/docker/api/errdefs" containertypes "github.com/docker/docker/api/types/container" networktypes "github.com/docker/docker/api/types/network" "github.com/docker/docker/container" "github.com/docker/docker/daemon/network" + "github.com/docker/docker/errdefs" "github.com/docker/docker/opts" "github.com/docker/docker/pkg/stringid" "github.com/docker/docker/runconfig" diff --git a/daemon/container_operations_unix.go b/daemon/container_operations_unix.go index 9eff1ebfbc..9fe899b623 100644 --- a/daemon/container_operations_unix.go +++ b/daemon/container_operations_unix.go @@ -11,9 +11,9 @@ import ( "strconv" "time" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/container" "github.com/docker/docker/daemon/links" + "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/idtools" "github.com/docker/docker/pkg/mount" "github.com/docker/docker/pkg/stringid" diff --git a/daemon/create.go b/daemon/create.go index a9c9e775ad..54ce12c239 100644 --- a/daemon/create.go +++ b/daemon/create.go @@ -9,11 +9,11 @@ import ( "github.com/pkg/errors" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types" containertypes "github.com/docker/docker/api/types/container" networktypes "github.com/docker/docker/api/types/network" "github.com/docker/docker/container" + "github.com/docker/docker/errdefs" "github.com/docker/docker/image" "github.com/docker/docker/layer" "github.com/docker/docker/pkg/idtools" diff --git a/daemon/daemon.go b/daemon/daemon.go index dd8c100c83..0f05f5783a 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -18,7 +18,6 @@ import ( "sync" "time" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types" containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/swarm" @@ -29,6 +28,7 @@ import ( "github.com/docker/docker/daemon/exec" "github.com/docker/docker/daemon/logger" "github.com/docker/docker/daemon/network" + "github.com/docker/docker/errdefs" "github.com/sirupsen/logrus" // register graph drivers _ "github.com/docker/docker/daemon/graphdriver/register" diff --git a/daemon/daemon_test.go b/daemon/daemon_test.go index 44bf3414c0..8ca1f0dd57 100644 --- a/daemon/daemon_test.go +++ b/daemon/daemon_test.go @@ -7,9 +7,9 @@ import ( "runtime" "testing" - "github.com/docker/docker/api/errdefs" containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/container" + "github.com/docker/docker/errdefs" _ "github.com/docker/docker/pkg/discovery/memory" "github.com/docker/docker/pkg/idtools" "github.com/docker/docker/pkg/truncindex" diff --git a/daemon/delete.go b/daemon/delete.go index e6fc1a5264..5fb9b9a1d9 100644 --- a/daemon/delete.go +++ b/daemon/delete.go @@ -7,9 +7,9 @@ import ( "strings" "time" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types" "github.com/docker/docker/container" + "github.com/docker/docker/errdefs" "github.com/docker/docker/layer" "github.com/docker/docker/pkg/system" "github.com/docker/docker/volume" diff --git a/daemon/errors.go b/daemon/errors.go index b39f9d1720..e3a16b0586 100644 --- a/daemon/errors.go +++ b/daemon/errors.go @@ -5,7 +5,7 @@ import ( "strings" "syscall" - "github.com/docker/docker/api/errdefs" + "github.com/docker/docker/errdefs" "github.com/pkg/errors" "google.golang.org/grpc" ) diff --git a/daemon/exec.go b/daemon/exec.go index 9955053739..6fe107987a 100644 --- a/daemon/exec.go +++ b/daemon/exec.go @@ -8,12 +8,12 @@ import ( "golang.org/x/net/context" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/strslice" "github.com/docker/docker/container" "github.com/docker/docker/container/stream" "github.com/docker/docker/daemon/exec" + "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/pools" "github.com/docker/docker/pkg/signal" "github.com/docker/docker/pkg/term" diff --git a/daemon/export.go b/daemon/export.go index 6024f74259..66a0cca048 100644 --- a/daemon/export.go +++ b/daemon/export.go @@ -5,8 +5,8 @@ import ( "io" "runtime" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/container" + "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/ioutils" ) diff --git a/daemon/graphdriver/quota/errors.go b/daemon/graphdriver/quota/errors.go index 1741f2f5db..6d755904a8 100644 --- a/daemon/graphdriver/quota/errors.go +++ b/daemon/graphdriver/quota/errors.go @@ -1,6 +1,6 @@ package quota -import "github.com/docker/docker/api/errdefs" +import "github.com/docker/docker/errdefs" var ( _ errdefs.ErrNotImplemented = (*errQuotaNotSupported)(nil) diff --git a/daemon/image.go b/daemon/image.go index a59f0ff205..fdbd6e2be7 100644 --- a/daemon/image.go +++ b/daemon/image.go @@ -5,7 +5,7 @@ import ( "runtime" "github.com/docker/distribution/reference" - "github.com/docker/docker/api/errdefs" + "github.com/docker/docker/errdefs" "github.com/docker/docker/image" ) diff --git a/daemon/image_delete.go b/daemon/image_delete.go index a4b1299909..36ac2c7c68 100644 --- a/daemon/image_delete.go +++ b/daemon/image_delete.go @@ -6,9 +6,9 @@ import ( "time" "github.com/docker/distribution/reference" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types" "github.com/docker/docker/container" + "github.com/docker/docker/errdefs" "github.com/docker/docker/image" "github.com/docker/docker/pkg/stringid" "github.com/pkg/errors" diff --git a/daemon/image_pull.go b/daemon/image_pull.go index b59753ac00..4944721f9f 100644 --- a/daemon/image_pull.go +++ b/daemon/image_pull.go @@ -7,10 +7,10 @@ import ( dist "github.com/docker/distribution" "github.com/docker/distribution/reference" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types" "github.com/docker/docker/distribution" progressutils "github.com/docker/docker/distribution/utils" + "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/progress" "github.com/docker/docker/registry" "github.com/opencontainers/go-digest" diff --git a/daemon/import.go b/daemon/import.go index b41f8e579e..3ac83a9fa9 100644 --- a/daemon/import.go +++ b/daemon/import.go @@ -10,11 +10,11 @@ import ( "time" "github.com/docker/distribution/reference" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types/container" "github.com/docker/docker/builder/dockerfile" "github.com/docker/docker/builder/remotecontext" "github.com/docker/docker/dockerversion" + "github.com/docker/docker/errdefs" "github.com/docker/docker/image" "github.com/docker/docker/layer" "github.com/docker/docker/pkg/archive" diff --git a/daemon/inspect.go b/daemon/inspect.go index 25805b296e..cab4f9279c 100644 --- a/daemon/inspect.go +++ b/daemon/inspect.go @@ -4,7 +4,6 @@ import ( "fmt" "time" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/backend" networktypes "github.com/docker/docker/api/types/network" @@ -12,6 +11,7 @@ import ( "github.com/docker/docker/api/types/versions/v1p20" "github.com/docker/docker/container" "github.com/docker/docker/daemon/network" + "github.com/docker/docker/errdefs" volumestore "github.com/docker/docker/volume/store" "github.com/docker/go-connections/nat" ) diff --git a/daemon/kill.go b/daemon/kill.go index 5cde0d776d..ad6104bfe9 100644 --- a/daemon/kill.go +++ b/daemon/kill.go @@ -7,8 +7,8 @@ import ( "syscall" "time" - "github.com/docker/docker/api/errdefs" containerpkg "github.com/docker/docker/container" + "github.com/docker/docker/errdefs" "github.com/docker/docker/libcontainerd" "github.com/docker/docker/pkg/signal" "github.com/pkg/errors" diff --git a/daemon/list.go b/daemon/list.go index 73d3f56769..8598d25280 100644 --- a/daemon/list.go +++ b/daemon/list.go @@ -6,10 +6,10 @@ import ( "strconv" "strings" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/container" + "github.com/docker/docker/errdefs" "github.com/docker/docker/image" "github.com/docker/docker/volume" "github.com/docker/go-connections/nat" diff --git a/daemon/logs.go b/daemon/logs.go index 612aeecb14..c819768dc3 100644 --- a/daemon/logs.go +++ b/daemon/logs.go @@ -7,13 +7,13 @@ import ( "golang.org/x/net/context" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/backend" containertypes "github.com/docker/docker/api/types/container" timetypes "github.com/docker/docker/api/types/time" "github.com/docker/docker/container" "github.com/docker/docker/daemon/logger" + "github.com/docker/docker/errdefs" "github.com/sirupsen/logrus" ) diff --git a/daemon/names.go b/daemon/names.go index da87447676..0e43738849 100644 --- a/daemon/names.go +++ b/daemon/names.go @@ -4,9 +4,9 @@ import ( "fmt" "strings" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/container" "github.com/docker/docker/daemon/names" + "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/namesgenerator" "github.com/docker/docker/pkg/stringid" "github.com/pkg/errors" diff --git a/daemon/network.go b/daemon/network.go index 3deb13ef88..35db27148a 100644 --- a/daemon/network.go +++ b/daemon/network.go @@ -8,10 +8,10 @@ import ( "strings" "sync" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/network" clustertypes "github.com/docker/docker/daemon/cluster/provider" + "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/plugingetter" "github.com/docker/docker/runconfig" "github.com/docker/libnetwork" diff --git a/daemon/rename.go b/daemon/rename.go index 14e66be1b5..fd13d898e2 100644 --- a/daemon/rename.go +++ b/daemon/rename.go @@ -3,8 +3,8 @@ package daemon import ( "strings" - "github.com/docker/docker/api/errdefs" dockercontainer "github.com/docker/docker/container" + "github.com/docker/docker/errdefs" "github.com/docker/libnetwork" "github.com/pkg/errors" "github.com/sirupsen/logrus" diff --git a/daemon/start.go b/daemon/start.go index 9509089f0f..aa080f7174 100644 --- a/daemon/start.go +++ b/daemon/start.go @@ -5,10 +5,10 @@ import ( "runtime" "time" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types" containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/container" + "github.com/docker/docker/errdefs" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) diff --git a/daemon/start_unix.go b/daemon/start_unix.go index 1efd07f959..ca0183ec5c 100644 --- a/daemon/start_unix.go +++ b/daemon/start_unix.go @@ -8,8 +8,8 @@ import ( "path/filepath" "github.com/containerd/containerd/linux/runctypes" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/container" + "github.com/docker/docker/errdefs" "github.com/pkg/errors" ) diff --git a/daemon/stop.go b/daemon/stop.go index 9b0bdcd2e3..d3b5297fb2 100644 --- a/daemon/stop.go +++ b/daemon/stop.go @@ -4,8 +4,8 @@ import ( "context" "time" - "github.com/docker/docker/api/errdefs" containerpkg "github.com/docker/docker/container" + "github.com/docker/docker/errdefs" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) diff --git a/daemon/update.go b/daemon/update.go index 49321934be..d2eb33a75e 100644 --- a/daemon/update.go +++ b/daemon/update.go @@ -4,8 +4,8 @@ import ( "context" "fmt" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types/container" + "github.com/docker/docker/errdefs" "github.com/pkg/errors" ) diff --git a/daemon/volumes.go b/daemon/volumes.go index 2e667c873d..2e75feebda 100644 --- a/daemon/volumes.go +++ b/daemon/volumes.go @@ -8,11 +8,11 @@ import ( "strings" "time" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types" containertypes "github.com/docker/docker/api/types/container" mounttypes "github.com/docker/docker/api/types/mount" "github.com/docker/docker/container" + "github.com/docker/docker/errdefs" "github.com/docker/docker/volume" "github.com/docker/docker/volume/drivers" "github.com/pkg/errors" diff --git a/distribution/errors.go b/distribution/errors.go index 3edeb3717f..49e8e5c0c1 100644 --- a/distribution/errors.go +++ b/distribution/errors.go @@ -12,8 +12,8 @@ import ( "github.com/docker/distribution/registry/api/v2" "github.com/docker/distribution/registry/client" "github.com/docker/distribution/registry/client/auth" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/distribution/xfer" + "github.com/docker/docker/errdefs" "github.com/sirupsen/logrus" ) diff --git a/errdefs/defs.go b/errdefs/defs.go new file mode 100644 index 0000000000..29c3619600 --- /dev/null +++ b/errdefs/defs.go @@ -0,0 +1,74 @@ +package errdefs + +// ErrNotFound signals that the requested object doesn't exist +type ErrNotFound interface { + NotFound() +} + +// ErrInvalidParameter signals that the user input is invalid +type ErrInvalidParameter interface { + InvalidParameter() +} + +// ErrConflict signals that some internal state conflicts with the requested action and can't be performed. +// A change in state should be able to clear this error. +type ErrConflict interface { + Conflict() +} + +// ErrUnauthorized is used to signify that the user is not authorized to perform a specific action +type ErrUnauthorized interface { + Unauthorized() +} + +// ErrUnavailable signals that the requested action/subsystem is not available. +type ErrUnavailable interface { + Unavailable() +} + +// ErrForbidden signals that the requested action cannot be performed under any circumstances. +// When a ErrForbidden is returned, the caller should never retry the action. +type ErrForbidden interface { + Forbidden() +} + +// ErrSystem signals that some internal error occurred. +// An example of this would be a failed mount request. +type ErrSystem interface { + ErrSystem() +} + +// ErrNotModified signals that an action can't be performed because it's already in the desired state +type ErrNotModified interface { + NotModified() +} + +// ErrAlreadyExists is a special case of ErrConflict which signals that the desired object already exists +type ErrAlreadyExists interface { + AlreadyExists() +} + +// ErrNotImplemented signals that the requested action/feature is not implemented on the system as configured. +type ErrNotImplemented interface { + NotImplemented() +} + +// ErrUnknown signals that the kind of error that occurred is not known. +type ErrUnknown interface { + Unknown() +} + +// ErrCancelled signals that the action was cancelled. +type ErrCancelled interface { + Cancelled() +} + +// ErrDeadline signals that the deadline was reached before the action completed. +type ErrDeadline interface { + DeadlineExceeded() +} + +// ErrDataLoss indicates that data was lost or there is data corruption. +type ErrDataLoss interface { + DataLoss() +} diff --git a/errdefs/doc.go b/errdefs/doc.go new file mode 100644 index 0000000000..065346aa29 --- /dev/null +++ b/errdefs/doc.go @@ -0,0 +1,8 @@ +// Package errdefs defines a set of error interfaces that packages should use for communicating classes of errors. +// Errors that cross the package boundary should implement one (and only one) of these interfaces. +// +// Packages should not reference these interfaces directly, only implement them. +// To check if a particular error implements one of these interfaces, there are helper +// functions provided (e.g. `Is`) which can be used rather than asserting the interfaces directly. +// If you must assert on these interfaces, be sure to check the causal chain (`err.Cause()`). +package errdefs diff --git a/errdefs/helpers.go b/errdefs/helpers.go new file mode 100644 index 0000000000..5afa944461 --- /dev/null +++ b/errdefs/helpers.go @@ -0,0 +1,240 @@ +package errdefs + +import "context" + +type errNotFound struct{ error } + +func (errNotFound) NotFound() {} + +func (e errNotFound) Cause() error { + return e.error +} + +// NotFound is a helper to create an error of the class with the same name from any error type +func NotFound(err error) error { + if err == nil { + return nil + } + return errNotFound{err} +} + +type errInvalidParameter struct{ error } + +func (errInvalidParameter) InvalidParameter() {} + +func (e errInvalidParameter) Cause() error { + return e.error +} + +// InvalidParameter is a helper to create an error of the class with the same name from any error type +func InvalidParameter(err error) error { + if err == nil { + return nil + } + return errInvalidParameter{err} +} + +type errConflict struct{ error } + +func (errConflict) Conflict() {} + +func (e errConflict) Cause() error { + return e.error +} + +// Conflict is a helper to create an error of the class with the same name from any error type +func Conflict(err error) error { + if err == nil { + return nil + } + return errConflict{err} +} + +type errUnauthorized struct{ error } + +func (errUnauthorized) Unauthorized() {} + +func (e errUnauthorized) Cause() error { + return e.error +} + +// Unauthorized is a helper to create an error of the class with the same name from any error type +func Unauthorized(err error) error { + if err == nil { + return nil + } + return errUnauthorized{err} +} + +type errUnavailable struct{ error } + +func (errUnavailable) Unavailable() {} + +func (e errUnavailable) Cause() error { + return e.error +} + +// Unavailable is a helper to create an error of the class with the same name from any error type +func Unavailable(err error) error { + return errUnavailable{err} +} + +type errForbidden struct{ error } + +func (errForbidden) Forbidden() {} + +func (e errForbidden) Cause() error { + return e.error +} + +// Forbidden is a helper to create an error of the class with the same name from any error type +func Forbidden(err error) error { + if err == nil { + return nil + } + return errForbidden{err} +} + +type errSystem struct{ error } + +func (errSystem) System() {} + +func (e errSystem) Cause() error { + return e.error +} + +// System is a helper to create an error of the class with the same name from any error type +func System(err error) error { + if err == nil { + return nil + } + return errSystem{err} +} + +type errNotModified struct{ error } + +func (errNotModified) NotModified() {} + +func (e errNotModified) Cause() error { + return e.error +} + +// NotModified is a helper to create an error of the class with the same name from any error type +func NotModified(err error) error { + if err == nil { + return nil + } + return errNotModified{err} +} + +type errAlreadyExists struct{ error } + +func (errAlreadyExists) AlreadyExists() {} + +func (e errAlreadyExists) Cause() error { + return e.error +} + +// AlreadyExists is a helper to create an error of the class with the same name from any error type +func AlreadyExists(err error) error { + if err == nil { + return nil + } + return errAlreadyExists{err} +} + +type errNotImplemented struct{ error } + +func (errNotImplemented) NotImplemented() {} + +func (e errNotImplemented) Cause() error { + return e.error +} + +// NotImplemented is a helper to create an error of the class with the same name from any error type +func NotImplemented(err error) error { + if err == nil { + return nil + } + return errNotImplemented{err} +} + +type errUnknown struct{ error } + +func (errUnknown) Unknown() {} + +func (e errUnknown) Cause() error { + return e.error +} + +// Unknown is a helper to create an error of the class with the same name from any error type +func Unknown(err error) error { + if err == nil { + return nil + } + return errUnknown{err} +} + +type errCancelled struct{ error } + +func (errCancelled) Cancelled() {} + +func (e errCancelled) Cause() error { + return e.error +} + +// Cancelled is a helper to create an error of the class with the same name from any error type +func Cancelled(err error) error { + if err == nil { + return nil + } + return errCancelled{err} +} + +type errDeadline struct{ error } + +func (errDeadline) DeadlineExceeded() {} + +func (e errDeadline) Cause() error { + return e.error +} + +// Deadline is a helper to create an error of the class with the same name from any error type +func Deadline(err error) error { + if err == nil { + return nil + } + return errDeadline{err} +} + +type errDataLoss struct{ error } + +func (errDataLoss) DataLoss() {} + +func (e errDataLoss) Cause() error { + return e.error +} + +// DataLoss is a helper to create an error of the class with the same name from any error type +func DataLoss(err error) error { + if err == nil { + return nil + } + return errDataLoss{err} +} + +// FromContext returns the error class from the passed in context +func FromContext(ctx context.Context) error { + e := ctx.Err() + if e == nil { + return nil + } + + if e == context.Canceled { + return Cancelled(e) + } + if e == context.DeadlineExceeded { + return Deadline(e) + } + return Unknown(e) +} diff --git a/errdefs/helpers_test.go b/errdefs/helpers_test.go new file mode 100644 index 0000000000..984f0a77a9 --- /dev/null +++ b/errdefs/helpers_test.go @@ -0,0 +1,132 @@ +package errdefs + +import ( + "errors" + "testing" +) + +var errTest = errors.New("this is a test") + +type causal interface { + Cause() error +} + +func TestNotFound(t *testing.T) { + e := NotFound(errTest) + if !IsNotFound(e) { + t.Fatalf("expected not found error, got: %T", e) + } + if cause := e.(causal).Cause(); cause != errTest { + t.Fatalf("causual should be errTest, got: %v", cause) + } +} + +func TestConflict(t *testing.T) { + e := Conflict(errTest) + if !IsConflict(e) { + t.Fatalf("expected conflcit error, got: %T", e) + } + if cause := e.(causal).Cause(); cause != errTest { + t.Fatalf("causual should be errTest, got: %v", cause) + } +} + +func TestForbidden(t *testing.T) { + e := Forbidden(errTest) + if !IsForbidden(e) { + t.Fatalf("expected forbidden error, got: %T", e) + } + if cause := e.(causal).Cause(); cause != errTest { + t.Fatalf("causual should be errTest, got: %v", cause) + } +} + +func TestInvalidParameter(t *testing.T) { + e := InvalidParameter(errTest) + if !IsInvalidParameter(e) { + t.Fatalf("expected invalid argument error, got %T", e) + } + if cause := e.(causal).Cause(); cause != errTest { + t.Fatalf("causual should be errTest, got: %v", cause) + } +} + +func TestNotImplemented(t *testing.T) { + e := NotImplemented(errTest) + if !IsNotImplemented(e) { + t.Fatalf("expected not implemented error, got %T", e) + } + if cause := e.(causal).Cause(); cause != errTest { + t.Fatalf("causual should be errTest, got: %v", cause) + } +} + +func TestNotModified(t *testing.T) { + e := NotModified(errTest) + if !IsNotModified(e) { + t.Fatalf("expected not modified error, got %T", e) + } + if cause := e.(causal).Cause(); cause != errTest { + t.Fatalf("causual should be errTest, got: %v", cause) + } +} + +func TestAlreadyExists(t *testing.T) { + e := AlreadyExists(errTest) + if !IsAlreadyExists(e) { + t.Fatalf("expected already exists error, got %T", e) + } + if cause := e.(causal).Cause(); cause != errTest { + t.Fatalf("causual should be errTest, got: %v", cause) + } +} + +func TestUnauthorized(t *testing.T) { + e := Unauthorized(errTest) + if !IsUnauthorized(e) { + t.Fatalf("expected unauthorized error, got %T", e) + } + if cause := e.(causal).Cause(); cause != errTest { + t.Fatalf("causual should be errTest, got: %v", cause) + } +} + +func TestUnknown(t *testing.T) { + e := Unknown(errTest) + if !IsUnknown(e) { + t.Fatalf("expected unknown error, got %T", e) + } + if cause := e.(causal).Cause(); cause != errTest { + t.Fatalf("causual should be errTest, got: %v", cause) + } +} + +func TestCancelled(t *testing.T) { + e := Cancelled(errTest) + if !IsCancelled(e) { + t.Fatalf("expected canclled error, got %T", e) + } + if cause := e.(causal).Cause(); cause != errTest { + t.Fatalf("causual should be errTest, got: %v", cause) + } +} + +func TestDeadline(t *testing.T) { + e := Deadline(errTest) + if !IsDeadline(e) { + t.Fatalf("expected deadline error, got %T", e) + } + if cause := e.(causal).Cause(); cause != errTest { + t.Fatalf("causual should be errTest, got: %v", cause) + } +} + +func TestIsDataLoss(t *testing.T) { + e := DataLoss(errTest) + if !IsDataLoss(e) { + t.Fatalf("expected data loss error, got %T", e) + } + if cause := e.(causal).Cause(); cause != errTest { + t.Fatalf("causual should be errTest, got: %v", cause) + } +} diff --git a/errdefs/is.go b/errdefs/is.go new file mode 100644 index 0000000000..286ffd694a --- /dev/null +++ b/errdefs/is.go @@ -0,0 +1,114 @@ +package errdefs + +type causer interface { + Cause() error +} + +func getImplementer(err error) error { + switch e := err.(type) { + case + ErrNotFound, + ErrInvalidParameter, + ErrConflict, + ErrUnauthorized, + ErrUnavailable, + ErrForbidden, + ErrSystem, + ErrNotModified, + ErrAlreadyExists, + ErrNotImplemented, + ErrCancelled, + ErrDeadline, + ErrDataLoss, + ErrUnknown: + return e + case causer: + return getImplementer(e.Cause()) + default: + return err + } +} + +// IsNotFound returns if the passed in error is an ErrNotFound +func IsNotFound(err error) bool { + _, ok := getImplementer(err).(ErrNotFound) + return ok +} + +// IsInvalidParameter returns if the passed in error is an ErrInvalidParameter +func IsInvalidParameter(err error) bool { + _, ok := getImplementer(err).(ErrInvalidParameter) + return ok +} + +// IsConflict returns if the passed in error is an ErrConflict +func IsConflict(err error) bool { + _, ok := getImplementer(err).(ErrConflict) + return ok +} + +// IsUnauthorized returns if the the passed in error is an ErrUnauthorized +func IsUnauthorized(err error) bool { + _, ok := getImplementer(err).(ErrUnauthorized) + return ok +} + +// IsUnavailable returns if the passed in error is an ErrUnavailable +func IsUnavailable(err error) bool { + _, ok := getImplementer(err).(ErrUnavailable) + return ok +} + +// IsForbidden returns if the passed in error is an ErrForbidden +func IsForbidden(err error) bool { + _, ok := getImplementer(err).(ErrForbidden) + return ok +} + +// IsSystem returns if the passed in error is an ErrSystem +func IsSystem(err error) bool { + _, ok := getImplementer(err).(ErrSystem) + return ok +} + +// IsNotModified returns if the passed in error is a NotModified error +func IsNotModified(err error) bool { + _, ok := getImplementer(err).(ErrNotModified) + return ok +} + +// IsAlreadyExists returns if the passed in error is a AlreadyExists error +func IsAlreadyExists(err error) bool { + _, ok := getImplementer(err).(ErrAlreadyExists) + return ok +} + +// IsNotImplemented returns if the passed in error is an ErrNotImplemented +func IsNotImplemented(err error) bool { + _, ok := getImplementer(err).(ErrNotImplemented) + return ok +} + +// IsUnknown returns if the passed in error is an ErrUnknown +func IsUnknown(err error) bool { + _, ok := getImplementer(err).(ErrUnknown) + return ok +} + +// IsCancelled returns if the passed in error is an ErrCancelled +func IsCancelled(err error) bool { + _, ok := getImplementer(err).(ErrCancelled) + return ok +} + +// IsDeadline returns if the passed in error is an ErrDeadline +func IsDeadline(err error) bool { + _, ok := getImplementer(err).(ErrDeadline) + return ok +} + +// IsDataLoss returns if the passed in error is an ErrDataLoss +func IsDataLoss(err error) bool { + _, ok := getImplementer(err).(ErrDataLoss) + return ok +} diff --git a/libcontainerd/client_daemon.go b/libcontainerd/client_daemon.go index cc0c099c43..9e66d224c6 100644 --- a/libcontainerd/client_daemon.go +++ b/libcontainerd/client_daemon.go @@ -31,7 +31,7 @@ import ( "github.com/containerd/containerd/images" "github.com/containerd/containerd/linux/runctypes" "github.com/containerd/typeurl" - "github.com/docker/docker/api/errdefs" + "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/ioutils" "github.com/opencontainers/image-spec/specs-go/v1" specs "github.com/opencontainers/runtime-spec/specs-go" diff --git a/libcontainerd/errors.go b/libcontainerd/errors.go index 1ecec7ba9d..dcd2525312 100644 --- a/libcontainerd/errors.go +++ b/libcontainerd/errors.go @@ -3,7 +3,7 @@ package libcontainerd import ( "errors" - "github.com/docker/docker/api/errdefs" + "github.com/docker/docker/errdefs" ) func newNotFoundError(err string) error { return errdefs.NotFound(errors.New(err)) } diff --git a/plugin/backend_linux.go b/plugin/backend_linux.go index 3437a7dca2..46bdfdbb1f 100644 --- a/plugin/backend_linux.go +++ b/plugin/backend_linux.go @@ -14,13 +14,13 @@ import ( "github.com/docker/distribution/manifest/schema2" "github.com/docker/distribution/reference" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/distribution" progressutils "github.com/docker/docker/distribution/utils" "github.com/docker/docker/distribution/xfer" "github.com/docker/docker/dockerversion" + "github.com/docker/docker/errdefs" "github.com/docker/docker/image" "github.com/docker/docker/layer" "github.com/docker/docker/pkg/authorization" diff --git a/plugin/executor/containerd/containerd.go b/plugin/executor/containerd/containerd.go index 38dcfcd58c..7b35136a1f 100644 --- a/plugin/executor/containerd/containerd.go +++ b/plugin/executor/containerd/containerd.go @@ -8,7 +8,7 @@ import ( "github.com/containerd/containerd/cio" "github.com/containerd/containerd/linux/runctypes" - "github.com/docker/docker/api/errdefs" + "github.com/docker/docker/errdefs" "github.com/docker/docker/libcontainerd" "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" diff --git a/plugin/manager_linux.go b/plugin/manager_linux.go index 888f06dd91..65380af06f 100644 --- a/plugin/manager_linux.go +++ b/plugin/manager_linux.go @@ -7,9 +7,9 @@ import ( "path/filepath" "time" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types" "github.com/docker/docker/daemon/initlayer" + "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/containerfs" "github.com/docker/docker/pkg/idtools" "github.com/docker/docker/pkg/mount" diff --git a/plugin/store.go b/plugin/store.go index 4ce817491c..9768c25068 100644 --- a/plugin/store.go +++ b/plugin/store.go @@ -5,7 +5,7 @@ import ( "strings" "github.com/docker/distribution/reference" - "github.com/docker/docker/api/errdefs" + "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/plugingetter" "github.com/docker/docker/pkg/plugins" "github.com/docker/docker/plugin/v2" diff --git a/registry/auth.go b/registry/auth.go index e91631701d..56b9c88295 100644 --- a/registry/auth.go +++ b/registry/auth.go @@ -10,9 +10,9 @@ import ( "github.com/docker/distribution/registry/client/auth" "github.com/docker/distribution/registry/client/auth/challenge" "github.com/docker/distribution/registry/client/transport" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types" registrytypes "github.com/docker/docker/api/types/registry" + "github.com/docker/docker/errdefs" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) diff --git a/registry/errors.go b/registry/errors.go index 1b8ea97f36..55f74d97ed 100644 --- a/registry/errors.go +++ b/registry/errors.go @@ -4,7 +4,7 @@ import ( "net/url" "github.com/docker/distribution/registry/api/errcode" - "github.com/docker/docker/api/errdefs" + "github.com/docker/docker/errdefs" ) type notFoundError string diff --git a/registry/service.go b/registry/service.go index ac240f0c69..bf4ab94d9f 100644 --- a/registry/service.go +++ b/registry/service.go @@ -11,9 +11,9 @@ import ( "github.com/docker/distribution/reference" "github.com/docker/distribution/registry/client/auth" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types" registrytypes "github.com/docker/docker/api/types/registry" + "github.com/docker/docker/errdefs" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) diff --git a/registry/session.go b/registry/session.go index 89c374f618..ae0ec1b4bf 100644 --- a/registry/session.go +++ b/registry/session.go @@ -19,9 +19,9 @@ import ( "github.com/docker/distribution/reference" "github.com/docker/distribution/registry/api/errcode" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types" registrytypes "github.com/docker/docker/api/types/registry" + "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/stringid" diff --git a/volume/local/local.go b/volume/local/local.go index 49e18b761a..206d96506c 100644 --- a/volume/local/local.go +++ b/volume/local/local.go @@ -13,8 +13,8 @@ import ( "strings" "sync" - "github.com/docker/docker/api/errdefs" "github.com/docker/docker/daemon/names" + "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/idtools" "github.com/docker/docker/pkg/mount" "github.com/docker/docker/volume" -- cgit v1.2.1