Przeglądaj źródła

Improve reference parse errors

Fixes #18093

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Tonis Tiigi 9 lat temu
rodzic
commit
15d84a3a48

+ 1 - 1
integration-cli/docker_cli_build_test.go

@@ -4614,7 +4614,7 @@ func (s *DockerSuite) TestBuildInvalidTag(c *check.C) {
 	_, out, err := buildImageWithOut(name, "FROM scratch\nMAINTAINER quux\n", true)
 	_, out, err := buildImageWithOut(name, "FROM scratch\nMAINTAINER quux\n", true)
 	// if the error doesn't check for illegal tag name, or the image is built
 	// if the error doesn't check for illegal tag name, or the image is built
 	// then this should fail
 	// then this should fail
-	if !strings.Contains(out, "invalid reference format") || strings.Contains(out, "Sending build context to Docker daemon") {
+	if !strings.Contains(out, "Error parsing reference") || strings.Contains(out, "Sending build context to Docker daemon") {
 		c.Fatalf("failed to stop before building. Error: %s, Output: %s", err, out)
 		c.Fatalf("failed to stop before building. Error: %s, Output: %s", err, out)
 	}
 	}
 }
 }

+ 1 - 1
integration-cli/docker_cli_create_test.go

@@ -265,7 +265,7 @@ func (s *DockerSuite) TestCreateByImageID(c *check.C) {
 		c.Fatalf("expected non-zero exit code; received %d", exit)
 		c.Fatalf("expected non-zero exit code; received %d", exit)
 	}
 	}
 
 
-	if expected := "invalid reference format"; !strings.Contains(out, expected) {
+	if expected := "Error parsing reference"; !strings.Contains(out, expected) {
 		c.Fatalf(`Expected %q in output; got: %s`, expected, out)
 		c.Fatalf(`Expected %q in output; got: %s`, expected, out)
 	}
 	}
 
 

+ 2 - 2
integration-cli/docker_cli_run_test.go

@@ -3758,8 +3758,8 @@ func (s *DockerSuite) TestRunInvalidReference(c *check.C) {
 		c.Fatalf("expected non-zero exist code; received %d", exit)
 		c.Fatalf("expected non-zero exist code; received %d", exit)
 	}
 	}
 
 
-	if !strings.Contains(out, "invalid reference format") {
-		c.Fatalf(`Expected "invalid reference format" in output; got: %s`, out)
+	if !strings.Contains(out, "Error parsing reference") {
+		c.Fatalf(`Expected "Error parsing reference" in output; got: %s`, out)
 	}
 	}
 }
 }
 
 

+ 3 - 3
integration-cli/docker_cli_tag_test.go

@@ -99,17 +99,17 @@ func (s *DockerSuite) TestTagWithPrefixHyphen(c *check.C) {
 	// test repository name begin with '-'
 	// test repository name begin with '-'
 	out, _, err := dockerCmdWithError("tag", "busybox:latest", "-busybox:test")
 	out, _, err := dockerCmdWithError("tag", "busybox:latest", "-busybox:test")
 	c.Assert(err, checker.NotNil, check.Commentf(out))
 	c.Assert(err, checker.NotNil, check.Commentf(out))
-	c.Assert(out, checker.Contains, "invalid reference format", check.Commentf("tag a name begin with '-' should failed"))
+	c.Assert(out, checker.Contains, "Error parsing reference", check.Commentf("tag a name begin with '-' should failed"))
 
 
 	// test namespace name begin with '-'
 	// test namespace name begin with '-'
 	out, _, err = dockerCmdWithError("tag", "busybox:latest", "-test/busybox:test")
 	out, _, err = dockerCmdWithError("tag", "busybox:latest", "-test/busybox:test")
 	c.Assert(err, checker.NotNil, check.Commentf(out))
 	c.Assert(err, checker.NotNil, check.Commentf(out))
-	c.Assert(out, checker.Contains, "invalid reference format", check.Commentf("tag a name begin with '-' should failed"))
+	c.Assert(out, checker.Contains, "Error parsing reference", check.Commentf("tag a name begin with '-' should failed"))
 
 
 	// test index name begin with '-'
 	// test index name begin with '-'
 	out, _, err = dockerCmdWithError("tag", "busybox:latest", "-index:5000/busybox:test")
 	out, _, err = dockerCmdWithError("tag", "busybox:latest", "-index:5000/busybox:test")
 	c.Assert(err, checker.NotNil, check.Commentf(out))
 	c.Assert(err, checker.NotNil, check.Commentf(out))
-	c.Assert(out, checker.Contains, "invalid reference format", check.Commentf("tag a name begin with '-' should failed"))
+	c.Assert(out, checker.Contains, "Error parsing reference", check.Commentf("tag a name begin with '-' should failed"))
 }
 }
 
 
 // ensure tagging using official names works
 // ensure tagging using official names works

+ 1 - 1
reference/reference.go

@@ -54,7 +54,7 @@ type Canonical interface {
 func ParseNamed(s string) (Named, error) {
 func ParseNamed(s string) (Named, error) {
 	named, err := distreference.ParseNamed(s)
 	named, err := distreference.ParseNamed(s)
 	if err != nil {
 	if err != nil {
-		return nil, err
+		return nil, fmt.Errorf("Error parsing reference: %q is not a valid repository/tag", s)
 	}
 	}
 	r, err := WithName(named.Name())
 	r, err := WithName(named.Name())
 	if err != nil {
 	if err != nil {