mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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.
This commit is contained in:
parent
457375ea37
commit
3c67a28493
3 changed files with 15 additions and 1 deletions
1
AUTHORS
1
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>
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue