From a11d78578498e0669a80d871845baa118bceb7a9 Mon Sep 17 00:00:00 2001 From: Ilya Dmitrichenko Date: Thu, 11 Mar 2021 14:28:28 +0000 Subject: [PATCH 1/2] Include URL and method in `ErrUnexpectedStatus` This should help with debugging expected responses. Signed-off-by: Ilya Dmitrichenko --- remotes/errors/errors.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/remotes/errors/errors.go b/remotes/errors/errors.go index e58e4afea..519dbac10 100644 --- a/remotes/errors/errors.go +++ b/remotes/errors/errors.go @@ -27,9 +27,10 @@ var _ error = ErrUnexpectedStatus{} // ErrUnexpectedStatus is returned if a registry API request returned with unexpected HTTP status type ErrUnexpectedStatus struct { - Status string - StatusCode int - Body []byte + Status string + StatusCode int + Body []byte + RequestURL, RequestMethod string } func (e ErrUnexpectedStatus) Error() string { @@ -42,5 +43,14 @@ func NewUnexpectedStatusErr(resp *http.Response) error { if resp.Body != nil { b, _ = ioutil.ReadAll(io.LimitReader(resp.Body, 64000)) // 64KB } - return ErrUnexpectedStatus{Status: resp.Status, StatusCode: resp.StatusCode, Body: b} + err := ErrUnexpectedStatus{ + Body: b, + Status: resp.Status, + StatusCode: resp.StatusCode, + RequestMethod: resp.Request.Method, + } + if resp.Request.URL != nil { + err.RequestURL = resp.Request.URL.String() + } + return err } From d1b7784357f758ca7ad4041f5fd056960f50252d Mon Sep 17 00:00:00 2001 From: Ilya Dmitrichenko Date: Thu, 11 Mar 2021 14:29:30 +0000 Subject: [PATCH 2/2] Use `ErrUnexpectedStatus` more consistently Signed-off-by: Ilya Dmitrichenko --- remotes/docker/pusher.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remotes/docker/pusher.go b/remotes/docker/pusher.go index 94a270cb7..0da62f4f7 100644 --- a/remotes/docker/pusher.go +++ b/remotes/docker/pusher.go @@ -354,7 +354,7 @@ func (pw *pushWriter) Commit(ctx context.Context, size int64, expected digest.Di switch resp.StatusCode { case http.StatusOK, http.StatusCreated, http.StatusNoContent, http.StatusAccepted: default: - return errors.Errorf("unexpected status: %s", resp.Status) + return remoteserrors.NewUnexpectedStatusErr(resp.Response) } status, err := pw.tracker.GetStatus(pw.ref)