1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #12999 from duglin/BadRUNerrMsg

Fix RUN's error msg when it fails
This commit is contained in:
Brian Goff 2015-05-06 15:49:24 -04:00
commit f9b20ad9e4
3 changed files with 23 additions and 1 deletions

View file

@ -619,7 +619,7 @@ func (b *Builder) run(c *daemon.Container) error {
// Wait for it to finish
if ret, _ := c.WaitStop(-1 * time.Second); ret != 0 {
return &jsonmessage.JSONError{
Message: fmt.Sprintf("The command %v returned a non-zero code: %d", b.Config.Cmd, ret),
Message: fmt.Sprintf("The command %q returned a non-zero code: %d", b.Config.Cmd.ToString(), ret),
Code: ret,
}
}

View file

@ -5384,3 +5384,20 @@ func (s *DockerSuite) TestBuildBadCmdFlag(c *check.C) {
c.Fatalf("Bad output\nGot:%s\n\nExpected to contain:%s\n", out, exp)
}
}
func (s *DockerSuite) TestBuildRUNErrMsg(c *check.C) {
// Test to make sure the bad command is quoted with just "s and
// not as a Go []string
name := "testbuildbadrunerrmsg"
_, out, err := buildImageWithOut(name, `
FROM busybox
RUN badEXE a1 a2`, false)
if err == nil {
c.Fatal("Should have failed to build")
}
exp := `The command \"/bin/sh -c badEXE a1 a2\" returned a non-zero code: 127"`
if !strings.Contains(out, exp) {
c.Fatalf("RUN doesn't have the correct output:\nGot:%s\nExpected:%s", out, exp)
}
}

View file

@ -3,6 +3,7 @@ package runconfig
import (
"encoding/json"
"io"
"strings"
"github.com/docker/docker/nat"
)
@ -59,6 +60,10 @@ type Command struct {
parts []string
}
func (e *Command) ToString() string {
return strings.Join(e.parts, " ")
}
func (e *Command) MarshalJSON() ([]byte, error) {
if e == nil {
return []byte{}, nil