Browse code

client: don't hide context errors

Instead of reformatting error from the request action, we wrap it,
allowing the cause to be recovered. This is important for consumers that
need to be able to detect context errors, such as `Cancelled` and
`DeadlineExceeded`.

Signed-off-by: Stephen J Day <stephen.day@docker.com>

Stephen J Day authored on 2016/09/09 07:37:45
Showing 3 changed files
... ...
@@ -14,6 +14,7 @@ import (
14 14
 	"github.com/docker/docker/api/types"
15 15
 	"github.com/docker/docker/api/types/versions"
16 16
 	"github.com/docker/docker/client/transport/cancellable"
17
+	"github.com/pkg/errors"
17 18
 	"golang.org/x/net/context"
18 19
 )
19 20
 
... ...
@@ -131,7 +132,8 @@ func (cli *Client) sendClientRequest(ctx context.Context, method, path string, q
131 131
 				}
132 132
 			}
133 133
 		}
134
-		return serverResp, fmt.Errorf("An error occurred trying to connect: %v", err)
134
+
135
+		return serverResp, errors.Wrap(err, "error during connect")
135 136
 	}
136 137
 
137 138
 	if resp != nil {
... ...
@@ -1703,7 +1703,7 @@ func (s *DockerDaemonSuite) TestDaemonNoTlsCliTlsVerifyWithEnv(c *check.C) {
1703 1703
 	cmd.Env = []string{"DOCKER_TLS_VERIFY=1", "DOCKER_CERT_PATH=fixtures/https"}
1704 1704
 	out, _, err := runCommandWithOutput(cmd)
1705 1705
 	c.Assert(err, check.Not(check.IsNil), check.Commentf("%s", out))
1706
-	c.Assert(strings.Contains(out, "error occurred trying to connect"), check.Equals, true)
1706
+	c.Assert(strings.Contains(out, "error during connect"), check.Equals, true)
1707 1707
 
1708 1708
 }
1709 1709
 
... ...
@@ -2662,7 +2662,7 @@ func (s *DockerSuite) TestRunTLSverify(c *check.C) {
2662 2662
 	// Regardless of whether we specify true or false we need to
2663 2663
 	// test to make sure tls is turned on if --tlsverify is specified at all
2664 2664
 	result := dockerCmdWithResult("--tlsverify=false", "ps")
2665
-	result.Assert(c, icmd.Expected{ExitCode: 1, Err: "trying to connect"})
2665
+	result.Assert(c, icmd.Expected{ExitCode: 1, Err: "error during connect"})
2666 2666
 
2667 2667
 	result = dockerCmdWithResult("--tlsverify=true", "ps")
2668 2668
 	result.Assert(c, icmd.Expected{ExitCode: 1, Err: "cert"})