mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
integration-cli: remove/rename err-returns and remove naked returns
Prevent accidentally shadowing these errors, which are used in defers, and remove naked returns. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -263,17 +263,16 @@ func (s *DockerCLILogsSuite) TestLogsFollowSlowStdoutConsumer(c *testing.T) {
|
||||
// ConsumeWithSpeed reads chunkSize bytes from reader before sleeping
|
||||
// for interval duration. Returns total read bytes. Send true to the
|
||||
// stop channel to return before reading to EOF on the reader.
|
||||
func ConsumeWithSpeed(reader io.Reader, chunkSize int, interval time.Duration, stop chan bool) (n int, err error) {
|
||||
func ConsumeWithSpeed(reader io.Reader, chunkSize int, interval time.Duration, stop chan bool) (n int, _ error) {
|
||||
buffer := make([]byte, chunkSize)
|
||||
for {
|
||||
var readBytes int
|
||||
readBytes, err = reader.Read(buffer)
|
||||
readBytes, err := reader.Read(buffer)
|
||||
n += readBytes
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
err = nil
|
||||
if err != io.EOF {
|
||||
return n, err
|
||||
}
|
||||
return n, err
|
||||
return n, nil
|
||||
}
|
||||
select {
|
||||
case <-stop:
|
||||
|
||||
@@ -67,8 +67,9 @@ func RandomTmpDirPath(s string, platform string) string {
|
||||
// of each pipelined with the following (like cmd1 | cmd2 | cmd3 would do).
|
||||
// It returns the final output, the exitCode different from 0 and the error
|
||||
// if something bad happened.
|
||||
//
|
||||
// Deprecated: use icmd instead
|
||||
func RunCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, err error) {
|
||||
func RunCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, retErr error) {
|
||||
if len(cmds) < 2 {
|
||||
return "", errors.New("pipeline does not have multiple cmds")
|
||||
}
|
||||
@@ -77,6 +78,7 @@ func RunCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, err error)
|
||||
for i, cmd := range cmds {
|
||||
if i > 0 {
|
||||
prevCmd := cmds[i-1]
|
||||
var err error
|
||||
cmd.Stdin, err = prevCmd.StdoutPipe()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot set stdout pipe for %s: %v", cmd.Path, err)
|
||||
@@ -86,7 +88,7 @@ func RunCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, err error)
|
||||
|
||||
// start all cmds except the last
|
||||
for _, cmd := range cmds[:len(cmds)-1] {
|
||||
if err = cmd.Start(); err != nil {
|
||||
if err := cmd.Start(); err != nil {
|
||||
return "", fmt.Errorf("starting %s failed with error: %v", cmd.Path, err)
|
||||
}
|
||||
}
|
||||
@@ -95,12 +97,12 @@ func RunCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, err error)
|
||||
var pipeErrMsgs []string
|
||||
// wait all cmds except the last to release their resources
|
||||
for _, cmd := range cmds[:len(cmds)-1] {
|
||||
if pipeErr := cmd.Wait(); pipeErr != nil {
|
||||
pipeErrMsgs = append(pipeErrMsgs, fmt.Sprintf("command %s failed with error: %v", cmd.Path, pipeErr))
|
||||
if err := cmd.Wait(); err != nil {
|
||||
pipeErrMsgs = append(pipeErrMsgs, fmt.Sprintf("command %s failed with error: %v", cmd.Path, err))
|
||||
}
|
||||
}
|
||||
if len(pipeErrMsgs) > 0 && err == nil {
|
||||
err = fmt.Errorf("pipelineError from Wait: %v", strings.Join(pipeErrMsgs, ", "))
|
||||
if len(pipeErrMsgs) > 0 && retErr == nil {
|
||||
retErr = fmt.Errorf("pipelineError from Wait: %v", strings.Join(pipeErrMsgs, ", "))
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user