66 "path"
77
88 "github.com/Sirupsen/logrus"
9+ derr "github.com/docker/docker/errors"
910 "github.com/docker/docker/volume/store"
1011)
1112
@@ -31,11 +32,11 @@ func (daemon *Daemon) ContainerRm(name string, config *ContainerRmConfig) error
3132 }
3233 parent , n := path .Split (name )
3334 if parent == "/" {
34- return fmt . Errorf ( "Conflict, cannot remove the default name of the container" )
35+ return derr . ErrorCodeDefaultName
3536 }
3637 pe := daemon .containerGraph ().Get (parent )
3738 if pe == nil {
38- return fmt . Errorf ( "Cannot get parent %s for name %s" , parent , name )
39+ return derr . ErrorCodeNoParent . WithArgs ( parent , name )
3940 }
4041
4142 if err := daemon .containerGraph ().Delete (name ); err != nil {
@@ -53,7 +54,8 @@ func (daemon *Daemon) ContainerRm(name string, config *ContainerRmConfig) error
5354 }
5455
5556 if err := daemon .rm (container , config .ForceRemove ); err != nil {
56- return fmt .Errorf ("Cannot destroy container %s: %v" , name , err )
57+ // return derr.ErrorCodeCantDestroy.WithArgs(name, utils.GetErrorMessage(err))
58+ return err
5759 }
5860
5961 if err := container .removeMountPoints (config .RemoveVolume ); err != nil {
@@ -67,10 +69,10 @@ func (daemon *Daemon) ContainerRm(name string, config *ContainerRmConfig) error
6769func (daemon * Daemon ) rm (container * Container , forceRemove bool ) (err error ) {
6870 if container .IsRunning () {
6971 if ! forceRemove {
70- return fmt . Errorf ( "Conflict, You cannot remove a running container. Stop the container before attempting removal or use -f" )
72+ return derr . ErrorCodeRmRunning
7173 }
7274 if err := container .Kill (); err != nil {
73- return fmt . Errorf ( "Could not kill running container, cannot remove - %v" , err )
75+ return derr . ErrorCodeRmFailed . WithArgs ( err )
7476 }
7577 }
7678
@@ -80,12 +82,12 @@ func (daemon *Daemon) rm(container *Container, forceRemove bool) (err error) {
8082
8183 element := daemon .containers .Get (container .ID )
8284 if element == nil {
83- return fmt . Errorf ( "Container %v not found - maybe it was already destroyed?" , container .ID )
85+ return derr . ErrorCodeRmNotFound . WithArgs ( container .ID )
8486 }
8587
8688 // Container state RemovalInProgress should be used to avoid races.
8789 if err = container .setRemovalInProgress (); err != nil {
88- return fmt . Errorf ( "Failed to set container state to RemovalInProgress: %s" , err )
90+ return derr . ErrorCodeRmState . WithArgs ( err )
8991 }
9092
9193 defer container .resetRemovalInProgress ()
@@ -120,20 +122,20 @@ func (daemon *Daemon) rm(container *Container, forceRemove bool) (err error) {
120122 }
121123
122124 if err = daemon .driver .Remove (container .ID ); err != nil {
123- return fmt . Errorf ( "Driver %s failed to remove root filesystem %s: %s" , daemon .driver , container .ID , err )
125+ return derr . ErrorCodeRmDriverFS . WithArgs ( daemon .driver , container .ID , err )
124126 }
125127
126128 initID := fmt .Sprintf ("%s-init" , container .ID )
127129 if err := daemon .driver .Remove (initID ); err != nil {
128- return fmt . Errorf ( "Driver %s failed to remove init filesystem %s: %s" , daemon .driver , initID , err )
130+ return derr . ErrorCodeRmInit . WithArgs ( daemon .driver , initID , err )
129131 }
130132
131133 if err = os .RemoveAll (container .root ); err != nil {
132- return fmt . Errorf ( "Unable to remove filesystem for %v: %v" , container .ID , err )
134+ return derr . ErrorCodeRmFS . WithArgs ( container .ID , err )
133135 }
134136
135137 if err = daemon .execDriver .Clean (container .ID ); err != nil {
136- return fmt . Errorf ( "Unable to remove execdriver data for %s: %s" , container .ID , err )
138+ return derr . ErrorCodeRmExecDriver . WithArgs ( container .ID , err )
137139 }
138140
139141 selinuxFreeLxcContexts (container .ProcessLabel )
@@ -154,9 +156,9 @@ func (daemon *Daemon) VolumeRm(name string) error {
154156 }
155157 if err := daemon .volumes .Remove (v ); err != nil {
156158 if err == store .ErrVolumeInUse {
157- return fmt . Errorf ( "Conflict: %v" , err )
159+ return derr . ErrorCodeRmVolumeInUse . WithArgs ( err )
158160 }
159- return fmt . Errorf ( "Error while removing volume %s: %v" , name , err )
161+ return derr . ErrorCodeRmVolume . WithArgs ( name , err )
160162 }
161163 return nil
162164}
0 commit comments