Browse Source

Merge pull request #2638 from FreakyDazio/2506-name-conflict-error

More informative error message on name collisions
Michael Crosby 11 years ago
parent
commit
75dd1663e0
3 changed files with 15 additions and 1 deletions
  1. 1 0
      AUTHORS
  2. 12 0
      integration/runtime_test.go
  3. 2 1
      runtime.go

+ 1 - 0
AUTHORS

@@ -44,6 +44,7 @@ Daniel Nordberg <dnordberg@gmail.com>
 Daniel Robinson <gottagetmac@gmail.com>
 Daniel Von Fange <daniel@leancoder.com>
 Daniel YC Lin <dlin.tw@gmail.com>
+Darren Coxall <darren@darrencoxall.com>
 David Calavera <david.calavera@gmail.com>
 David Sissitka <me@dsissitka.com>
 Deni Bertovic <deni@kset.org>

+ 12 - 0
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")

+ 2 - 1
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
 	}