45067cda33
The wrapResponseError() utility converted some specific errors, but in
doing so, could hide the actual error message returned by the daemon.
In addition, starting with 38e6d474af
,
HTTP status codes were already mapped to their corresponding errdefs
types on the client-side, making this conversion redundant.
This patch removes the wrapResponseError() utility; it's worth noting
that some error-messages will change slightly (as they now return the
error as returned by the daemon), but may cointain more details as
before, and in some cases prevents hiding the actual error.
Before this change:
docker container rm nosuchcontainer
Error: No such container: nosuchcontainer
docker container cp mycontainer:/no/such/path .
Error: No such container:path: mycontainer:/no/such/path
docker container cp ./Dockerfile mycontainer:/no/such/path
Error: No such container:path: mycontainer:/no/such
docker image rm nosuchimage
Error: No such image: nosuchimage
docker network rm nosuchnetwork
Error: No such network: nosuchnetwork
docker volume rm nosuchvolume
Error: No such volume: nosuchvolume
docker plugin rm nosuchplugin
Error: No such plugin: nosuchplugin
docker checkpoint rm nosuchcontainer nosuchcheckpoint
Error response from daemon: No such container: nosuchcontainer
docker checkpoint rm mycontainer nosuchcheckpoint
Error response from daemon: checkpoint nosuchcheckpoint does not exist for container mycontainer
docker service rm nosuchservice
Error: No such service: nosuchservice
docker node rm nosuchnode
Error: No such node: nosuchnode
docker config rm nosuschconfig
Error: No such config: nosuschconfig
docker secret rm nosuchsecret
Error: No such secret: nosuchsecret
After this change:
docker container rm nosuchcontainer
Error response from daemon: No such container: nosuchcontainer
docker container cp mycontainer:/no/such/path .
Error response from daemon: Could not find the file /no/such/path in container mycontainer
docker container cp ./Dockerfile mycontainer:/no/such/path
Error response from daemon: Could not find the file /no/such in container mycontainer
docker image rm nosuchimage
Error response from daemon: No such image: nosuchimage:latest
docker network rm nosuchnetwork
Error response from daemon: network nosuchnetwork not found
docker volume rm nosuchvolume
Error response from daemon: get nosuchvolume: no such volume
docker plugin rm nosuchplugin
Error response from daemon: plugin "nosuchplugin" not found
docker checkpoint rm nosuchcontainer nosuchcheckpoint
Error response from daemon: No such container: nosuchcontainer
docker checkpoint rm mycontainer nosuchcheckpoint
Error response from daemon: checkpoint nosuchcheckpoint does not exist for container mycontainer
docker service rm nosuchservice
Error response from daemon: service nosuchservice not found
docker node rm nosuchnode
Error response from daemon: node nosuchnode not found
docker config rm nosuchconfig
Error response from daemon: config nosuchconfig not found
docker secret rm nosuchsecret
Error response from daemon: secret nosuchsecret not found
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
124 lines
3.4 KiB
Go
124 lines
3.4 KiB
Go
package client // import "github.com/docker/docker/client"
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/docker/docker/api/types/versions"
|
|
"github.com/docker/docker/errdefs"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// errConnectionFailed implements an error returned when connection failed.
|
|
type errConnectionFailed struct {
|
|
host string
|
|
}
|
|
|
|
// Error returns a string representation of an errConnectionFailed
|
|
func (err errConnectionFailed) Error() string {
|
|
if err.host == "" {
|
|
return "Cannot connect to the Docker daemon. Is the docker daemon running on this host?"
|
|
}
|
|
return fmt.Sprintf("Cannot connect to the Docker daemon at %s. Is the docker daemon running?", err.host)
|
|
}
|
|
|
|
// IsErrConnectionFailed returns true if the error is caused by connection failed.
|
|
func IsErrConnectionFailed(err error) bool {
|
|
return errors.As(err, &errConnectionFailed{})
|
|
}
|
|
|
|
// ErrorConnectionFailed returns an error with host in the error message when connection to docker daemon failed.
|
|
func ErrorConnectionFailed(host string) error {
|
|
return errConnectionFailed{host: host}
|
|
}
|
|
|
|
// Deprecated: use the errdefs.NotFound() interface instead. Kept for backward compatibility
|
|
type notFound interface {
|
|
error
|
|
NotFound() bool
|
|
}
|
|
|
|
// IsErrNotFound returns true if the error is a NotFound error, which is returned
|
|
// by the API when some object is not found.
|
|
func IsErrNotFound(err error) bool {
|
|
var e notFound
|
|
if errors.As(err, &e) {
|
|
return true
|
|
}
|
|
return errdefs.IsNotFound(err)
|
|
}
|
|
|
|
type objectNotFoundError struct {
|
|
object string
|
|
id string
|
|
}
|
|
|
|
func (e objectNotFoundError) NotFound() {}
|
|
|
|
func (e objectNotFoundError) Error() string {
|
|
return fmt.Sprintf("Error: No such %s: %s", e.object, e.id)
|
|
}
|
|
|
|
// unauthorizedError represents an authorization error in a remote registry.
|
|
type unauthorizedError struct {
|
|
cause error
|
|
}
|
|
|
|
// Error returns a string representation of an unauthorizedError
|
|
func (u unauthorizedError) Error() string {
|
|
return u.cause.Error()
|
|
}
|
|
|
|
// IsErrUnauthorized returns true if the error is caused
|
|
// when a remote registry authentication fails
|
|
func IsErrUnauthorized(err error) bool {
|
|
if _, ok := err.(unauthorizedError); ok {
|
|
return ok
|
|
}
|
|
return errdefs.IsUnauthorized(err)
|
|
}
|
|
|
|
type pluginPermissionDenied struct {
|
|
name string
|
|
}
|
|
|
|
func (e pluginPermissionDenied) Error() string {
|
|
return "Permission denied while installing plugin " + e.name
|
|
}
|
|
|
|
// IsErrPluginPermissionDenied returns true if the error is caused
|
|
// when a user denies a plugin's permissions
|
|
func IsErrPluginPermissionDenied(err error) bool {
|
|
_, ok := err.(pluginPermissionDenied)
|
|
return ok
|
|
}
|
|
|
|
type notImplementedError struct {
|
|
message string
|
|
}
|
|
|
|
func (e notImplementedError) Error() string {
|
|
return e.message
|
|
}
|
|
|
|
func (e notImplementedError) NotImplemented() bool {
|
|
return true
|
|
}
|
|
|
|
// IsErrNotImplemented returns true if the error is a NotImplemented error.
|
|
// This is returned by the API when a requested feature has not been
|
|
// implemented.
|
|
func IsErrNotImplemented(err error) bool {
|
|
if _, ok := err.(notImplementedError); ok {
|
|
return ok
|
|
}
|
|
return errdefs.IsNotImplemented(err)
|
|
}
|
|
|
|
// NewVersionError returns an error if the APIVersion required
|
|
// if less than the current supported version
|
|
func (cli *Client) NewVersionError(APIrequired, feature string) error {
|
|
if cli.version != "" && versions.LessThan(cli.version, APIrequired) {
|
|
return fmt.Errorf("%q requires API version %s, but the Docker daemon API version is %s", feature, APIrequired, cli.version)
|
|
}
|
|
return nil
|
|
}
|