@@ -872,7 +872,7 @@ func (ic *ContainerEngine) ContainerRun(ctx context.Context, opts entities.Conta
872
872
for _ , w := range con .Warnings {
873
873
fmt .Fprintf (os .Stderr , "%s\n " , w )
874
874
}
875
- removeContainer := func (id , CIDFile string , force bool ) error {
875
+ removeContainer := func (id , CIDFile string , force bool ) {
876
876
if CIDFile != "" {
877
877
if err := os .Remove (CIDFile ); err != nil && ! errors .Is (err , os .ErrNotExist ) {
878
878
logrus .Warnf ("Cleaning up CID file: %s" , err )
@@ -882,13 +882,12 @@ func (ic *ContainerEngine) ContainerRun(ctx context.Context, opts entities.Conta
882
882
removeOptions := new (containers.RemoveOptions ).WithVolumes (true ).WithForce (force )
883
883
reports , err := containers .Remove (ic .ClientCtx , id , removeOptions )
884
884
logIfRmError (id , err , reports )
885
- return err
886
885
}
887
886
888
887
if opts .CIDFile != "" {
889
888
if err := util .CreateIDFile (opts .CIDFile , con .ID ); err != nil {
890
889
// If you fail to create CIDFile then remove the container
891
- _ = removeContainer (con .ID , opts .CIDFile , true )
890
+ removeContainer (con .ID , opts .CIDFile , true )
892
891
return nil , err
893
892
}
894
893
}
@@ -901,7 +900,7 @@ func (ic *ContainerEngine) ContainerRun(ctx context.Context, opts entities.Conta
901
900
if err != nil {
902
901
report .ExitCode = define .ExitCode (err )
903
902
if opts .Rm {
904
- _ = removeContainer (con .ID , opts .CIDFile , true )
903
+ removeContainer (con .ID , opts .CIDFile , true )
905
904
}
906
905
}
907
906
return & report , err
@@ -924,15 +923,13 @@ func (ic *ContainerEngine) ContainerRun(ctx context.Context, opts entities.Conta
924
923
925
924
report .ExitCode = define .ExitCode (err )
926
925
if opts .Rm {
927
- _ = removeContainer (con .ID , opts .CIDFile , false )
926
+ removeContainer (con .ID , opts .CIDFile , false )
928
927
}
929
928
return & report , err
930
929
}
931
930
932
931
if opts .Rm {
933
- // Defer the removal, so we can return early if needed and
934
- // de-spaghetti the code.
935
- defer removeContainer (con .ID , opts .CIDFile , false )
932
+ removeContainer (con .ID , opts .CIDFile , false )
936
933
}
937
934
938
935
report .ExitCode = code
0 commit comments