From 37475a876686f870285d82585e69433ab9fef7a4 Mon Sep 17 00:00:00 2001 From: Benjamin Elder Date: Tue, 2 Oct 2018 23:19:48 -0700 Subject: [PATCH] correct docker.Run error handling --- pkg/docker/docker.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/docker/docker.go b/pkg/docker/docker.go index d7cb10007c..4950b1c103 100644 --- a/pkg/docker/docker.go +++ b/pkg/docker/docker.go @@ -19,6 +19,7 @@ limitations under the License. package docker import ( + "fmt" "regexp" "time" @@ -72,15 +73,20 @@ func Run(image string, runArgs []string, containerArgs []string) (id string, err cmd.Args = append(cmd.Args, containerArgs...) cmd.Debug = true output, err := cmd.CombinedOutputLines() - // if docker created a container the id will be the first line and match - if len(output) > 0 && containerIDRegex.MatchString(output[0]) { - id = output[0] - } - // log error lines if there were any if err != nil { + // log error output if there was any for _, line := range output { log.Error(line) } + return "", err + } + // if docker created a container the id will be the first line and match + // validate the output and get the id + if len(output) < 1 { + return "", fmt.Errorf("failed to get container id, received no output from docker run") + } + if !containerIDRegex.MatchString(output[0]) { + return "", fmt.Errorf("failed to get container id, output did not match: %v", output) } - return id, nil + return output[0], nil }