mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
fix incorrect ErrConnectFailed comparison
Signed-off-by: Reficul <xuzhenglun@gmail.com>
This commit is contained in:
parent
5c6e649fde
commit
d5dc9b8b1f
3 changed files with 22 additions and 6 deletions
|
@ -170,7 +170,7 @@ func getExecExitCode(ctx context.Context, client apiclient.ContainerAPIClient, e
|
||||||
resp, err := client.ContainerExecInspect(ctx, execID)
|
resp, err := client.ContainerExecInspect(ctx, execID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If we can't connect, then the daemon probably died.
|
// If we can't connect, then the daemon probably died.
|
||||||
if err != apiclient.ErrConnectionFailed {
|
if !apiclient.IsErrConnectionFailed(err) {
|
||||||
return false, -1, err
|
return false, -1, err
|
||||||
}
|
}
|
||||||
return false, -1, nil
|
return false, -1, nil
|
||||||
|
|
|
@ -91,7 +91,7 @@ func getExitCode(ctx context.Context, dockerCli *command.DockerCli, containerID
|
||||||
c, err := dockerCli.Client().ContainerInspect(ctx, containerID)
|
c, err := dockerCli.Client().ContainerInspect(ctx, containerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If we can't connect, then the daemon probably died.
|
// If we can't connect, then the daemon probably died.
|
||||||
if err != clientapi.ErrConnectionFailed {
|
if !clientapi.IsErrConnectionFailed(err) {
|
||||||
return false, -1, err
|
return false, -1, err
|
||||||
}
|
}
|
||||||
return false, -1, nil
|
return false, -1, nil
|
||||||
|
|
|
@ -1,18 +1,34 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/versions"
|
"github.com/docker/docker/api/types/versions"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrConnectionFailed is an error raised when the connection between the client and the server failed.
|
// errConnectionFailed implements an error returned when connection failed.
|
||||||
var ErrConnectionFailed = errors.New("Cannot connect to the Docker daemon. Is the docker daemon running on this host?")
|
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 {
|
||||||
|
_, ok := errors.Cause(err).(errConnectionFailed)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
// ErrorConnectionFailed returns an error with host in the error message when connection to docker daemon failed.
|
// ErrorConnectionFailed returns an error with host in the error message when connection to docker daemon failed.
|
||||||
func ErrorConnectionFailed(host string) error {
|
func ErrorConnectionFailed(host string) error {
|
||||||
return fmt.Errorf("Cannot connect to the Docker daemon at %s. Is the docker daemon running?", host)
|
return errConnectionFailed{host: host}
|
||||||
}
|
}
|
||||||
|
|
||||||
type notFound interface {
|
type notFound interface {
|
||||||
|
|
Loading…
Reference in a new issue