Skip to content

Commit 462d0ff

Browse files
committed
client: Client.doRequest: simplify permission check and unwrap error
Previously, we were using os.IsPermission, which doesn't unwrap errors; change to use `errors.Is` to detect permission errors, and unwrap the error to remove information about the request, which is irrelevant if we weren't able to connect in the first place. Also tweak the error slightly to not assume "docker socket", instead mentioning "docker API". Before this; permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.51/version": dial unix /var/run/docker.sock: connect: permission denied With this patch applied: permission denied while trying to connect to the docker API at unix:///var/run/docker.sock: dial unix /var/run/docker.sock: connect: permission denied Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 7072aca commit 462d0ff

2 files changed

Lines changed: 8 additions & 16 deletions

File tree

client/request.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,10 @@ func (cli *Client) doRequest(req *http.Request) (*http.Response, error) {
153153
return nil, err
154154
}
155155

156-
var uErr *url.Error
157-
if errors.As(err, &uErr) {
158-
var nErr *net.OpError
159-
if errors.As(uErr.Err, &nErr) {
160-
if os.IsPermission(nErr.Err) {
161-
return nil, errConnectionFailed{errors.Wrapf(err, "permission denied while trying to connect to the Docker daemon socket at %v", cli.host)}
162-
}
163-
}
156+
if errors.Is(err, os.ErrPermission) {
157+
// Don't include request errors ("Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.51/version"),
158+
// which are irrelevant if we weren't able to connect.
159+
return nil, errConnectionFailed{fmt.Errorf("permission denied while trying to connect to the docker API at %v", cli.host)}
164160
}
165161

166162
var nErr net.Error

vendor/github.com/moby/moby/client/request.go

Lines changed: 4 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)