Skip to content

Commit

Permalink
Merge pull request moby#2638 from FreakyDazio/2506-name-conflict-error
Browse files Browse the repository at this point in the history
More informative error message on name collisions
  • Loading branch information
crosbymichael committed Nov 18, 2013
2 parents 457375e + 3c67a28 commit 75dd166
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Daniel Nordberg <[email protected]>
Daniel Robinson <[email protected]>
Daniel Von Fange <[email protected]>
Daniel YC Lin <[email protected]>
Darren Coxall <[email protected]>
David Calavera <[email protected]>
David Sissitka <[email protected]>
Deni Bertovic <[email protected]>
Expand Down
12 changes: 12 additions & 0 deletions integration/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 75dd166

Please sign in to comment.