Browse code

Add the mediaType to the error

Without this fix the error the client might see is:
target is unknown
which wasn't helpful to me when I saw this today. With this fix I
now see:
MediaType is unknown: 'text/html'
which helped me track down the issue to the registry I was talking to.

Signed-off-by: Doug Davis <dug@us.ibm.com>

Doug Davis authored on 2017/01/11 12:27:55
Showing 4 changed files
... ...
@@ -76,7 +76,7 @@ func runPull(dockerCli *command.DockerCli, opts pullOptions) error {
76 76
 		err = imagePullPrivileged(ctx, dockerCli, authConfig, reference.FamiliarString(distributionRef), requestPrivilege, opts.all)
77 77
 	}
78 78
 	if err != nil {
79
-		if strings.Contains(err.Error(), "target is plugin") {
79
+		if strings.Contains(err.Error(), "when fetching 'plugin'") {
80 80
 			return errors.New(err.Error() + " - Use `docker plugin install`")
81 81
 		}
82 82
 		return err
... ...
@@ -152,7 +152,7 @@ func runInstall(dockerCli *command.DockerCli, opts pluginOptions) error {
152 152
 
153 153
 	responseBody, err := dockerCli.Client().PluginInstall(ctx, alias, options)
154 154
 	if err != nil {
155
-		if strings.Contains(err.Error(), "target is image") {
155
+		if strings.Contains(err.Error(), "(image) when fetching") {
156 156
 			return errors.New(err.Error() + " - Use `docker image pull`")
157 157
 		}
158 158
 		return err
... ...
@@ -363,7 +363,7 @@ func (p *v2Puller) pullV2Tag(ctx context.Context, ref reference.Named) (tagUpdat
363 363
 			if configClass == "" {
364 364
 				configClass = "unknown"
365 365
 			}
366
-			return false, fmt.Errorf("target is %s", configClass)
366
+			return false, fmt.Errorf("Encountered remote %q(%s) when fetching", m.Manifest.Config.MediaType, configClass)
367 367
 		}
368 368
 	}
369 369
 
... ...
@@ -181,7 +181,7 @@ func (s *DockerRegistrySuite) TestPluginInstallImage(c *check.C) {
181 181
 
182 182
 	out, _, err := dockerCmdWithError("plugin", "install", repoName)
183 183
 	c.Assert(err, checker.NotNil)
184
-	c.Assert(out, checker.Contains, "target is image")
184
+	c.Assert(out, checker.Contains, `Encountered remote "application/vnd.docker.container.image.v1+json"(image) when fetching`)
185 185
 }
186 186
 
187 187
 func (s *DockerSuite) TestPluginEnableDisableNegative(c *check.C) {