Browse code

Fix RUN's error msg when it fails

When RUN returns with a non-zero return code it prints the command
that was executed as a Go []string:
```
INFO[0000] The command &{[/bin/sh -c noop a1 a2]} returned a non-zero code: 127
```

instead it should look like this:
```
INFO[0000] The command "/bin/sh -c noop a1 a2" returned a non-zero code: 127
```

Signed-off-by: Doug Davis <dug@us.ibm.com>

Doug Davis authored on 2015/05/06 05:00:20
Showing 3 changed files
... ...
@@ -619,7 +619,7 @@ func (b *Builder) run(c *daemon.Container) error {
619 619
 	// Wait for it to finish
620 620
 	if ret, _ := c.WaitStop(-1 * time.Second); ret != 0 {
621 621
 		return &jsonmessage.JSONError{
622
-			Message: fmt.Sprintf("The command %v returned a non-zero code: %d", b.Config.Cmd, ret),
622
+			Message: fmt.Sprintf("The command %q returned a non-zero code: %d", b.Config.Cmd.ToString(), ret),
623 623
 			Code:    ret,
624 624
 		}
625 625
 	}
... ...
@@ -5384,3 +5384,20 @@ func (s *DockerSuite) TestBuildBadCmdFlag(c *check.C) {
5384 5384
 		c.Fatalf("Bad output\nGot:%s\n\nExpected to contain:%s\n", out, exp)
5385 5385
 	}
5386 5386
 }
5387
+
5388
+func (s *DockerSuite) TestBuildRUNErrMsg(c *check.C) {
5389
+	// Test to make sure the bad command is quoted with just "s and
5390
+	// not as a Go []string
5391
+	name := "testbuildbadrunerrmsg"
5392
+	_, out, err := buildImageWithOut(name, `
5393
+  FROM busybox
5394
+  RUN badEXE a1 a2`, false)
5395
+	if err == nil {
5396
+		c.Fatal("Should have failed to build")
5397
+	}
5398
+
5399
+	exp := `The command \"/bin/sh -c badEXE a1 a2\" returned a non-zero code: 127"`
5400
+	if !strings.Contains(out, exp) {
5401
+		c.Fatalf("RUN doesn't have the correct output:\nGot:%s\nExpected:%s", out, exp)
5402
+	}
5403
+}
... ...
@@ -3,6 +3,7 @@ package runconfig
3 3
 import (
4 4
 	"encoding/json"
5 5
 	"io"
6
+	"strings"
6 7
 
7 8
 	"github.com/docker/docker/nat"
8 9
 )
... ...
@@ -59,6 +60,10 @@ type Command struct {
59 59
 	parts []string
60 60
 }
61 61
 
62
+func (e *Command) ToString() string {
63
+	return strings.Join(e.parts, " ")
64
+}
65
+
62 66
 func (e *Command) MarshalJSON() ([]byte, error) {
63 67
 	if e == nil {
64 68
 		return []byte{}, nil