mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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>
This commit is contained in:
parent
b5d68944f4
commit
54662eae10
3 changed files with 23 additions and 1 deletions
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue