mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
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:
@@ -9,6 +9,7 @@ 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"
|
||||
@@ -136,12 +137,12 @@ func (daemon *Daemon) Commit(name string, c *backend.ContainerCommitConfig) (str
|
||||
|
||||
if container.IsDead() {
|
||||
err := fmt.Errorf("You cannot commit container %s which is Dead", container.ID)
|
||||
return "", stateConflictError{err}
|
||||
return "", errdefs.Conflict(err)
|
||||
}
|
||||
|
||||
if container.IsRemovalInProgress() {
|
||||
err := fmt.Errorf("You cannot commit container %s which is being removed", container.ID)
|
||||
return "", stateConflictError{err}
|
||||
return "", errdefs.Conflict(err)
|
||||
}
|
||||
|
||||
if c.Pause && !container.IsPaused() {
|
||||
|
||||
Reference in New Issue
Block a user