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:
commit
f9b20ad9e4
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
|
// Wait for it to finish
|
||||||
if ret, _ := c.WaitStop(-1 * time.Second); ret != 0 {
|
if ret, _ := c.WaitStop(-1 * time.Second); ret != 0 {
|
||||||
return &jsonmessage.JSONError{
|
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,
|
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)
|
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 (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/nat"
|
"github.com/docker/docker/nat"
|
||||||
)
|
)
|
||||||
|
@ -59,6 +60,10 @@ type Command struct {
|
||||||
parts []string
|
parts []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *Command) ToString() string {
|
||||||
|
return strings.Join(e.parts, " ")
|
||||||
|
}
|
||||||
|
|
||||||
func (e *Command) MarshalJSON() ([]byte, error) {
|
func (e *Command) MarshalJSON() ([]byte, error) {
|
||||||
if e == nil {
|
if e == nil {
|
||||||
return []byte{}, nil
|
return []byte{}, nil
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue