From 3c67a2849337f3b9bd92dd389f0e02e48a36028b Mon Sep 17 00:00:00 2001 From: Darren Coxall Date: Sun, 10 Nov 2013 21:50:34 +0000 Subject: [PATCH] More informative error message on name collisions This is the proposed fix for #2506. It provides a more complete message with regards to name collisions including informing of the opposing containers ID. I have included a test to ensure that the correct short id is displayed to make the message easier to understand. --- AUTHORS | 1 + integration/runtime_test.go | 12 ++++++++++++ runtime.go | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 214c87ce25..60533c1cc2 100644 --- a/AUTHORS +++ b/AUTHORS @@ -44,6 +44,7 @@ Daniel Nordberg Daniel Robinson Daniel Von Fange Daniel YC Lin +Darren Coxall David Calavera David Sissitka Deni Bertovic diff --git a/integration/runtime_test.go b/integration/runtime_test.go index fb928d8160..320a3645b0 100644 --- a/integration/runtime_test.go +++ b/integration/runtime_test.go @@ -231,6 +231,18 @@ func TestRuntimeCreate(t *testing.T) { t.Errorf("Exists() returned false for a newly created container") } + // Test that conflict error displays correct details + testContainer, _, _ := runtime.Create( + &docker.Config{ + Image: GetTestImage(runtime).ID, + Cmd: []string{"ls", "-al"}, + }, + "conflictname", + ) + if _, _, err := runtime.Create(&docker.Config{Image: GetTestImage(runtime).ID, Cmd: []string{"ls", "-al"}}, testContainer.Name); err == nil || !strings.Contains(err.Error(), utils.TruncateID(testContainer.ID)) { + t.Fatalf("Name conflict error doesn't include the correct short id. Message was: %s", err.Error()) + } + // Make sure create with bad parameters returns an error if _, _, err = runtime.Create(&docker.Config{Image: GetTestImage(runtime).ID}, ""); err == nil { t.Fatal("Builder.Create should throw an error when Cmd is missing") diff --git a/runtime.go b/runtime.go index 4559164e28..f8c15767d7 100644 --- a/runtime.go +++ b/runtime.go @@ -402,7 +402,8 @@ func (runtime *Runtime) Create(config *Config, name string) (*Container, []strin // Set the enitity in the graph using the default name specified if _, err := runtime.containerGraph.Set(name, id); err != nil { if strings.HasSuffix(err.Error(), "name are not unique") { - return nil, nil, fmt.Errorf("Conflict, %s already exists.", name) + conflictingContainer, _ := runtime.GetByName(name) + return nil, nil, fmt.Errorf("Conflict, The name %s is already assigned to %s. You have to delete (or rename) that container to be able to assign %s to a container again.", name, utils.TruncateID(conflictingContainer.ID), name) } return nil, nil, err }