diff options
author | Derek McGowan <derek@mcgstyle.net> | 2016-11-10 15:14:33 -0800 |
---|---|---|
committer | Derek McGowan <derek@mcgstyle.net> | 2016-11-10 17:34:12 -0800 |
commit | 19a93a6e3d4213c56583bb0c843cf9e33d379752 (patch) | |
tree | ed2710b04363e975743139778d5942a56e4f12c3 /distribution/errors.go | |
parent | c85eb008416f352327b67dce351101591cd5f781 (diff) | |
download | docker-19a93a6e3d4213c56583bb0c843cf9e33d379752.tar.gz |
Update pull error handling
Translate pull errors to provide a more consistent and user friendly
error message.
Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
Diffstat (limited to 'distribution/errors.go')
-rw-r--r-- | distribution/errors.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/distribution/errors.go b/distribution/errors.go index 1e7630e380..ed8c3c0534 100644 --- a/distribution/errors.go +++ b/distribution/errors.go @@ -5,11 +5,14 @@ import ( "strings" "syscall" + "github.com/Sirupsen/logrus" "github.com/docker/distribution/registry/api/errcode" "github.com/docker/distribution/registry/api/v2" "github.com/docker/distribution/registry/client" "github.com/docker/distribution/registry/client/auth" "github.com/docker/docker/distribution/xfer" + "github.com/docker/docker/reference" + "github.com/pkg/errors" ) // ErrNoSupport is an error type used for errors indicating that an operation @@ -56,6 +59,37 @@ func shouldV2Fallback(err errcode.Error) bool { return false } +func translatePullError(err error, ref reference.Named) error { + switch v := err.(type) { + case errcode.Errors: + if len(v) != 0 { + for _, extra := range v[1:] { + logrus.Infof("Ignoring extra error returned from registry: %v", extra) + } + return translatePullError(v[0], ref) + } + case errcode.Error: + var newErr error + switch v.Code { + case errcode.ErrorCodeDenied: + // ErrorCodeDenied is used when access to the repository was denied + newErr = errors.Errorf("repository %s not found: does not exist or no read access", ref.Name()) + case v2.ErrorCodeManifestUnknown: + newErr = errors.Errorf("manifest for %s not found", ref.String()) + case v2.ErrorCodeNameUnknown: + newErr = errors.Errorf("repository %s not found", ref.Name()) + } + if newErr != nil { + logrus.Infof("Translating %q to %q", err, newErr) + return newErr + } + case xfer.DoNotRetry: + return translatePullError(v.Err, ref) + } + + return err +} + // continueOnError returns true if we should fallback to the next endpoint // as a result of this error. func continueOnError(err error) bool { |