From 15d84a3a48efa12ed8bdc500f28ca58a7b1d1083 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Wed, 9 Dec 2015 23:31:38 -0800 Subject: [PATCH] Improve reference parse errors Fixes #18093 Signed-off-by: Tonis Tiigi --- integration-cli/docker_cli_build_test.go | 2 +- integration-cli/docker_cli_create_test.go | 2 +- integration-cli/docker_cli_run_test.go | 4 ++-- integration-cli/docker_cli_tag_test.go | 6 +++--- reference/reference.go | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index b540af51c8..13001068f9 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/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) // if the error doesn't check for illegal tag name, or the image is built // 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) } } diff --git a/integration-cli/docker_cli_create_test.go b/integration-cli/docker_cli_create_test.go index cac5b92d5c..a2d47cf595 100644 --- a/integration-cli/docker_cli_create_test.go +++ b/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) } - 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) } diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index 3bab96fb2f..399dce27cb 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/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) } - 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) } } diff --git a/integration-cli/docker_cli_tag_test.go b/integration-cli/docker_cli_tag_test.go index 7e27a750d2..de5d547ebe 100644 --- a/integration-cli/docker_cli_tag_test.go +++ b/integration-cli/docker_cli_tag_test.go @@ -99,17 +99,17 @@ func (s *DockerSuite) TestTagWithPrefixHyphen(c *check.C) { // test repository name begin with '-' out, _, err := dockerCmdWithError("tag", "busybox:latest", "-busybox:test") 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 '-' out, _, err = dockerCmdWithError("tag", "busybox:latest", "-test/busybox:test") 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 '-' out, _, err = dockerCmdWithError("tag", "busybox:latest", "-index:5000/busybox:test") 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 diff --git a/reference/reference.go b/reference/reference.go index d2d733587a..8e887e3637 100644 --- a/reference/reference.go +++ b/reference/reference.go @@ -54,7 +54,7 @@ type Canonical interface { func ParseNamed(s string) (Named, error) { named, err := distreference.ParseNamed(s) 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()) if err != nil {