Skip to content

Commit d001281

Browse files
dploegerDennis Ploeger
authored andcommitted
fix: Added missing error handling for when Docker crashes
1 parent 23cbdcd commit d001281

1 file changed

Lines changed: 25 additions & 7 deletions

File tree

internal/adapters/docker.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/docker/docker/client"
1717
resty "github.com/go-resty/resty/v2"
1818
"github.com/moby/term"
19+
"github.com/sirupsen/logrus"
1920
"io"
2021
"net"
2122
"os"
@@ -140,8 +141,13 @@ func (d *DockerAdapter) RunCloudControl(_ string, name string, consoleWidth uint
140141
case <-quitWriter:
141142
return
142143
default:
143-
if b, err := s.ReadByte(); err == nil {
144-
_, _ = stdout.Write([]byte{b})
144+
if b, err := s.ReadByte(); err != nil {
145+
logrus.Errorf("error reading from Docker: %s", err)
146+
return
147+
} else {
148+
if _, err := stdout.Write([]byte{b}); err != nil {
149+
logrus.Errorf("error writing to stdout: %s", err)
150+
}
145151
}
146152
}
147153
}
@@ -154,8 +160,14 @@ func (d *DockerAdapter) RunCloudControl(_ string, name string, consoleWidth uint
154160
case <-quitReader:
155161
return
156162
default:
157-
if b, err := s.ReadByte(); err == nil {
158-
_, _ = c.Write([]byte{b})
163+
if b, err := s.ReadByte(); err != nil {
164+
logrus.Errorf("error reading from Docker: %s", err)
165+
return
166+
} else {
167+
if _, err := c.Write([]byte{b}); err != nil {
168+
logrus.Errorf("error writing to Docker: %s", err)
169+
return
170+
}
159171
}
160172
}
161173
}
@@ -169,14 +181,20 @@ func (d *DockerAdapter) RunCloudControl(_ string, name string, consoleWidth uint
169181
case <-quitTermResize:
170182
return
171183
default:
172-
if w, err := term.GetWinsize(fd); err == nil {
184+
if w, err := term.GetWinsize(fd); err != nil {
185+
logrus.Errorf("error getting terminal size: %s", err)
186+
return
187+
} else {
173188
if w.Width != uint16(width) || w.Height != uint16(height) {
174189
width = uint(w.Width)
175190
height = uint(w.Height)
176-
_ = dockerCli.ContainerExecResize(context.Background(), executeID, types.ResizeOptions{
191+
if err := dockerCli.ContainerExecResize(context.Background(), executeID, types.ResizeOptions{
177192
Width: width,
178193
Height: height,
179-
})
194+
}); err != nil {
195+
logrus.Errorf("error resizing container terminal: %s", err)
196+
return
197+
}
180198
}
181199
}
182200
}

0 commit comments

Comments
 (0)