diff --git a/internal/registry/auth.go b/internal/registry/auth.go index 1c0ccb6759..4844710e66 100644 --- a/internal/registry/auth.go +++ b/internal/registry/auth.go @@ -8,6 +8,7 @@ import ( "strings" "time" + "github.com/containerd/errdefs/pkg/errhttp" "github.com/containerd/log" "github.com/docker/distribution/registry/client/auth" "github.com/docker/distribution/registry/client/auth/challenge" @@ -67,11 +68,7 @@ func loginV2(ctx context.Context, authConfig *registry.AuthConfig, endpoint APIE if resp.StatusCode != http.StatusOK { // TODO(dmcgowan): Attempt to further interpret result, status code and error code string - err := fmt.Errorf("login attempt to %s failed with status: %d %s", endpointStr, resp.StatusCode, http.StatusText(resp.StatusCode)) - if resp.StatusCode == http.StatusUnauthorized { - return "", unauthorizedErr{err} - } - return "", err + return "", fmt.Errorf("login attempt to %s failed with status: %d %s: %w", endpointStr, resp.StatusCode, http.StatusText(resp.StatusCode), errhttp.ToNative(resp.StatusCode)) } return credentialAuthConfig.IdentityToken, nil diff --git a/internal/registry/auth_test.go b/internal/registry/auth_test.go index 4b7f1a8d5b..44632df42e 100644 --- a/internal/registry/auth_test.go +++ b/internal/registry/auth_test.go @@ -33,6 +33,7 @@ func TestLoginV2BasicAuthUnauthorized(t *testing.T) { _, err = loginV2(ctx, ®istry.AuthConfig{Username: "alice", Password: "wrong"}, endpoint, "docker-test") assert.ErrorContains(t, err, "401") assert.Check(t, errdefs.IsUnauthorized(err)) + assert.Check(t, is.ErrorType(err, errdefs.IsUnauthorized)) token, err := loginV2(ctx, ®istry.AuthConfig{Username: "alice", Password: "secret"}, endpoint, "docker-test") assert.NilError(t, err) diff --git a/vendor.mod b/vendor.mod index 0a21b03055..ea519df145 100644 --- a/vendor.mod +++ b/vendor.mod @@ -14,6 +14,7 @@ tool ( require ( dario.cat/mergo v1.0.2 github.com/containerd/errdefs v1.0.0 + github.com/containerd/errdefs/pkg v0.3.0 github.com/containerd/log v0.1.0 github.com/containerd/platforms v1.0.0-rc.5 github.com/creack/pty v1.1.24 @@ -75,7 +76,6 @@ require ( github.com/cenkalti/backoff/v5 v5.0.3 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/clipperhouse/uax29/v2 v2.2.0 // indirect - github.com/containerd/errdefs/pkg v0.3.0 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect github.com/docker/go-events v0.0.0-20260608200158-dbf6103125a4 // indirect github.com/docker/go-metrics v0.1.0 // indirect