From 50de9fdff11065cbc9783be07ad1b78a35b6bbac Mon Sep 17 00:00:00 2001 From: David Calavera Date: Mon, 1 Feb 2016 15:30:58 -0500 Subject: [PATCH] Make error message consistent when removing containers fail. Signed-off-by: David Calavera --- api/client/rm.go | 24 +++++++++++++++--------- api/client/run.go | 16 ++++++---------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/api/client/rm.go b/api/client/rm.go index a6c4d9d5b9..f4e3c58233 100644 --- a/api/client/rm.go +++ b/api/client/rm.go @@ -28,15 +28,8 @@ func (cli *DockerCli) CmdRm(args ...string) error { } name = strings.Trim(name, "/") - options := types.ContainerRemoveOptions{ - ContainerID: name, - RemoveVolumes: *v, - RemoveLinks: *link, - Force: *force, - } - - if err := cli.client.ContainerRemove(options); err != nil { - errs = append(errs, fmt.Sprintf("Failed to remove container (%s): %s", name, err)) + if err := cli.removeContainer(name, *v, *link, *force); err != nil { + errs = append(errs, err.Error()) } else { fmt.Fprintf(cli.out, "%s\n", name) } @@ -46,3 +39,16 @@ func (cli *DockerCli) CmdRm(args ...string) error { } return nil } + +func (cli *DockerCli) removeContainer(containerID string, removeVolumes, removeLinks, force bool) error { + options := types.ContainerRemoveOptions{ + ContainerID: containerID, + RemoveVolumes: removeVolumes, + RemoveLinks: removeLinks, + Force: force, + } + if err := cli.client.ContainerRemove(options); err != nil { + return fmt.Errorf("Failed to remove container (%s): %v", containerID, err) + } + return nil +} diff --git a/api/client/run.go b/api/client/run.go index 16f4230e97..b73108d38d 100644 --- a/api/client/run.go +++ b/api/client/run.go @@ -218,17 +218,13 @@ func (cli *DockerCli) CmdRun(args ...string) error { }) } - defer func() { - if *flAutoRemove { - options := types.ContainerRemoveOptions{ - ContainerID: createResponse.ID, - RemoveVolumes: true, + if *flAutoRemove { + defer func() { + if err := cli.removeContainer(createResponse.ID, true, false, false); err != nil { + fmt.Fprintf(cli.err, "%v\n", err) } - if err := cli.client.ContainerRemove(options); err != nil { - fmt.Fprintf(cli.err, "Error deleting container: %s\n", err) - } - } - }() + }() + } //start the container if err := cli.client.ContainerStart(createResponse.ID); err != nil {