From b90c466c3858a119880b4a086d6362378760dabc Mon Sep 17 00:00:00 2001 From: W3QKR2T Date: Fri, 4 Mar 2022 10:46:39 +0100 Subject: [PATCH 1/2] Add ErrUnexpectedStatus to resolver Signed-off-by: Fabian Hoffmann --- remotes/docker/resolver.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/remotes/docker/resolver.go b/remotes/docker/resolver.go index 5feaee167..6e543b2c0 100644 --- a/remotes/docker/resolver.go +++ b/remotes/docker/resolver.go @@ -32,6 +32,7 @@ import ( "github.com/containerd/containerd/reference" "github.com/containerd/containerd/remotes" "github.com/containerd/containerd/remotes/docker/schema1" + remoteerrors "github.com/containerd/containerd/remotes/errors" "github.com/containerd/containerd/version" digest "github.com/opencontainers/go-digest" ocispec "github.com/opencontainers/image-spec/specs-go/v1" @@ -297,11 +298,11 @@ func (r *dockerResolver) Resolve(ctx context.Context, ref string) (string, ocisp if resp.StatusCode > 399 { // Set firstErr when encountering the first non-404 status code. if firstErr == nil { - firstErr = fmt.Errorf("pulling from host %s failed with status code %v: %v", host.Host, u, resp.Status) + firstErr = remoteerrors.NewUnexpectedStatusErr(resp) } continue // try another host } - return "", ocispec.Descriptor{}, fmt.Errorf("pulling from host %s failed with unexpected status code %v: %v", host.Host, u, resp.Status) + return "", ocispec.Descriptor{}, remoteerrors.NewUnexpectedStatusErr(resp) } size := resp.ContentLength contentType := getManifestMediaType(resp) From 894e7800149feb7c184c90ed117ad0f61838833d Mon Sep 17 00:00:00 2001 From: Fabian Hoffmann <35104465+FabHof@users.noreply.github.com> Date: Mon, 7 Mar 2022 09:46:25 +0100 Subject: [PATCH 2/2] Improve ErrUnexpectedStatus default string Signed-off-by: Fabian Hoffmann --- remotes/errors/errors.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remotes/errors/errors.go b/remotes/errors/errors.go index 67ccb23df..f60ff0fc2 100644 --- a/remotes/errors/errors.go +++ b/remotes/errors/errors.go @@ -33,7 +33,7 @@ type ErrUnexpectedStatus struct { } func (e ErrUnexpectedStatus) Error() string { - return fmt.Sprintf("unexpected status: %s", e.Status) + return fmt.Sprintf("unexpected status from %s request to %s: %s", e.RequestMethod, e.RequestURL, e.Status) } // NewUnexpectedStatusErr creates an ErrUnexpectedStatus from HTTP response