Signed-off-by: Reficul <xuzhenglun@gmail.com>
(cherry picked from commit d5dc9b8b1f5e693cfb3aace06e08e7fc6eb798d7)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
| ... | ... |
@@ -170,7 +170,7 @@ func getExecExitCode(ctx context.Context, client apiclient.ContainerAPIClient, e |
| 170 | 170 |
resp, err := client.ContainerExecInspect(ctx, execID) |
| 171 | 171 |
if err != nil {
|
| 172 | 172 |
// If we can't connect, then the daemon probably died. |
| 173 |
- if err != apiclient.ErrConnectionFailed {
|
|
| 173 |
+ if !apiclient.IsErrConnectionFailed(err) {
|
|
| 174 | 174 |
return false, -1, err |
| 175 | 175 |
} |
| 176 | 176 |
return false, -1, nil |
| ... | ... |
@@ -102,7 +102,7 @@ func getExitCode(dockerCli *command.DockerCli, ctx context.Context, containerID |
| 102 | 102 |
c, err := dockerCli.Client().ContainerInspect(ctx, containerID) |
| 103 | 103 |
if err != nil {
|
| 104 | 104 |
// If we can't connect, then the daemon probably died. |
| 105 |
- if err != clientapi.ErrConnectionFailed {
|
|
| 105 |
+ if !clientapi.IsErrConnectionFailed(err) {
|
|
| 106 | 106 |
return false, -1, err |
| 107 | 107 |
} |
| 108 | 108 |
return false, -1, nil |
| ... | ... |
@@ -1,18 +1,34 @@ |
| 1 | 1 |
package client |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "errors" |
|
| 5 | 4 |
"fmt" |
| 6 | 5 |
|
| 7 | 6 |
"github.com/docker/docker/api/types/versions" |
| 7 |
+ "github.com/pkg/errors" |
|
| 8 | 8 |
) |
| 9 | 9 |
|
| 10 |
-// ErrConnectionFailed is an error raised when the connection between the client and the server failed. |
|
| 11 |
-var ErrConnectionFailed = errors.New("Cannot connect to the Docker daemon. Is the docker daemon running on this host?")
|
|
| 10 |
+// errConnectionFailed implements an error returned when connection failed. |
|
| 11 |
+type errConnectionFailed struct {
|
|
| 12 |
+ host string |
|
| 13 |
+} |
|
| 14 |
+ |
|
| 15 |
+// Error returns a string representation of an errConnectionFailed |
|
| 16 |
+func (err errConnectionFailed) Error() string {
|
|
| 17 |
+ if err.host == "" {
|
|
| 18 |
+ return "Cannot connect to the Docker daemon. Is the docker daemon running on this host?" |
|
| 19 |
+ } |
|
| 20 |
+ return fmt.Sprintf("Cannot connect to the Docker daemon at %s. Is the docker daemon running?", err.host)
|
|
| 21 |
+} |
|
| 22 |
+ |
|
| 23 |
+// IsErrConnectionFailed returns true if the error is caused by connection failed. |
|
| 24 |
+func IsErrConnectionFailed(err error) bool {
|
|
| 25 |
+ _, ok := errors.Cause(err).(errConnectionFailed) |
|
| 26 |
+ return ok |
|
| 27 |
+} |
|
| 12 | 28 |
|
| 13 | 29 |
// ErrorConnectionFailed returns an error with host in the error message when connection to docker daemon failed. |
| 14 | 30 |
func ErrorConnectionFailed(host string) error {
|
| 15 |
- return fmt.Errorf("Cannot connect to the Docker daemon at %s. Is the docker daemon running?", host)
|
|
| 31 |
+ return errConnectionFailed{host: host}
|
|
| 16 | 32 |
} |
| 17 | 33 |
|
| 18 | 34 |
type notFound interface {
|