mirror of
https://github.com/docker/cli.git
synced 2026-11-14 00:33:51 -04:00
full diff: https://github.com/moby/moby/compare/402d0a16f131...client/v0.6.3 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
72 lines
2.1 KiB
Go
72 lines
2.1 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/moby/moby/client/pkg/versions"
|
|
)
|
|
|
|
// errConnectionFailed implements an error returned when connection failed.
|
|
type errConnectionFailed struct {
|
|
error
|
|
}
|
|
|
|
// Error returns a string representation of an errConnectionFailed
|
|
func (e errConnectionFailed) Error() string {
|
|
return e.error.Error()
|
|
}
|
|
|
|
func (e errConnectionFailed) Unwrap() error {
|
|
return e.error
|
|
}
|
|
|
|
// IsErrConnectionFailed returns true if the error is caused by connection failed.
|
|
func IsErrConnectionFailed(err error) bool {
|
|
return errors.As(err, &errConnectionFailed{})
|
|
}
|
|
|
|
// connectionFailed returns an error with host in the error message when connection
|
|
// to docker daemon failed.
|
|
func connectionFailed(host string) error {
|
|
var err error
|
|
if host == "" {
|
|
err = errors.New("Cannot connect to the Docker daemon. Is the docker daemon running on this host?")
|
|
} else {
|
|
err = fmt.Errorf("Cannot connect to the Docker daemon at %s. Is the docker daemon running?", host)
|
|
}
|
|
return errConnectionFailed{error: 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)
|
|
}
|
|
|
|
// requiresVersion returns an error if the APIVersion required is less than the
|
|
// current supported version.
|
|
//
|
|
// It performs API-version negotiation if the Client is configured with this
|
|
// option, otherwise it assumes the latest API version is used.
|
|
func (cli *Client) requiresVersion(ctx context.Context, apiRequired, feature string) error {
|
|
// Make sure we negotiated (if the client is configured to do so),
|
|
// as code below contains API-version specific handling of options.
|
|
//
|
|
// Normally, version-negotiation (if enabled) would not happen until
|
|
// the API request is made.
|
|
if err := cli.checkVersion(ctx); err != nil {
|
|
return err
|
|
}
|
|
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
|
|
}
|