Add helpers to create errdef errors

Instead of having to create a bunch of custom error types that are doing
nothing but wrapping another error in sub-packages, use a common helper
to create errors of the requested type.

e.g. instead of re-implementing this over and over:

```go
type notFoundError struct {
  cause error
}

func(e notFoundError) Error() string {
  return e.cause.Error()
}

func(e notFoundError) NotFound() {}

func(e notFoundError) Cause() error {
  return e.cause
}
```

Packages can instead just do:

```
  errdefs.NotFound(err)
```

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff
2017-11-28 23:09:37 -05:00
parent 92309e34e4
commit 87a12421a9
65 changed files with 682 additions and 661 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"github.com/docker/docker/api/errdefs"
"github.com/docker/docker/api/types/container"
"github.com/pkg/errors"
)
@@ -19,7 +20,7 @@ func (daemon *Daemon) ContainerUpdate(name string, hostConfig *container.HostCon
warnings, err = daemon.verifyContainerSettings(c.OS, hostConfig, nil, true)
if err != nil {
return container.ContainerUpdateOKBody{Warnings: warnings}, validationError{err}
return container.ContainerUpdateOKBody{Warnings: warnings}, errdefs.InvalidParameter(err)
}
if err := daemon.update(name, hostConfig); err != nil {
@@ -80,7 +81,7 @@ func (daemon *Daemon) update(name string, hostConfig *container.HostConfig) erro
if err := daemon.containerd.UpdateResources(context.Background(), container.ID, toContainerdResources(hostConfig.Resources)); err != nil {
restoreConfig = true
// TODO: it would be nice if containerd responded with better errors here so we can classify this better.
return errCannotUpdate(container.ID, systemError{err})
return errCannotUpdate(container.ID, errdefs.System(err))
}
}