Skip to content

Commit

Permalink
fix: added log entry in case of container delete failed
Browse files Browse the repository at this point in the history
  • Loading branch information
FMotalleb committed Jun 16, 2024
1 parent 8772de8 commit c81362b
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions core/cmd_connection/docker_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/FMotalleb/crontab-go/abstraction"
"github.com/FMotalleb/crontab-go/config"
"github.com/FMotalleb/crontab-go/helpers"
)

// DockerCreateConnection is a struct that manages the creation and execution of Docker containers.
Expand Down Expand Up @@ -127,10 +128,14 @@ func (d *DockerCreateConnection) Execute() ([]byte, error) {
if err != nil {
return nil, err
}
defer d.cli.ContainerRemove(ctx, exec.ID,
container.RemoveOptions{
Force: true,
},
defer helpers.WarnOnErr(
d.log,
d.cli.ContainerRemove(ctx, exec.ID,
container.RemoveOptions{
Force: true,
},
),
"Cannot remove the container: %s",
)
err = d.cli.ContainerStart(d.log.Context, exec.ID,
container.StartOptions{},
Expand Down Expand Up @@ -161,7 +166,11 @@ func (d *DockerCreateConnection) Execute() ([]byte, error) {
if err != nil {
return nil, err
}
defer resp.Close()
defer helpers.WarnOnErr(
d.log,
resp.Close(),
"cannot close the container's logs: %s",
)

writer := bytes.NewBuffer([]byte{})
// Print the command output
Expand Down

0 comments on commit c81362b

Please sign in to comment.