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.
Upstream-commit: 3c67a2849337f3b9bd92dd389f0e02e48a36028b
Component: engine
This commit is contained in:
Darren Coxall
2013-11-10 21:50:34 +00:00
parent 9f3980c29f
commit 6c91c91066
3 changed files with 15 additions and 1 deletions

View File

@ -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
}