mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #30039 from ripcurld0/specify_line_no_dockerfile_err
Specify in which line the Dockerfile parser failed
This commit is contained in:
commit
597843e790
2 changed files with 53 additions and 1 deletions
|
@ -264,7 +264,7 @@ func (b *Builder) build(stdout io.Writer, stderr io.Writer, out io.Writer) (stri
|
|||
total := len(b.dockerfile.Children)
|
||||
for _, n := range b.dockerfile.Children {
|
||||
if err := b.checkDispatch(n, false); err != nil {
|
||||
return "", err
|
||||
return "", perrors.Wrapf(err, "Dockerfile parse error line %d", n.StartLine)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7388,3 +7388,55 @@ func (s *DockerSuite) TestBuildWorkdirCmd(c *check.C) {
|
|||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(strings.Count(out, "Using cache"), checker.Equals, 1)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildLineErrorOnBuild(c *check.C) {
|
||||
name := "test_build_line_error_onbuild"
|
||||
|
||||
_, err := buildImage(name,
|
||||
`FROM busybox
|
||||
ONBUILD
|
||||
`, true)
|
||||
c.Assert(err.Error(), checker.Contains, "Dockerfile parse error line 2: ONBUILD requires at least one argument")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildLineErrorUknownInstruction(c *check.C) {
|
||||
name := "test_build_line_error_unknown_instruction"
|
||||
|
||||
_, err := buildImage(name,
|
||||
`FROM busybox
|
||||
RUN echo hello world
|
||||
NOINSTRUCTION echo ba
|
||||
RUN echo hello
|
||||
ERROR
|
||||
`, true)
|
||||
c.Assert(err.Error(), checker.Contains, "Dockerfile parse error line 3: Unknown instruction: NOINSTRUCTION")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildLineErrorWithEmptyLines(c *check.C) {
|
||||
name := "test_build_line_error_with_empty_lines"
|
||||
|
||||
_, err := buildImage(name,
|
||||
`
|
||||
FROM busybox
|
||||
|
||||
RUN echo hello world
|
||||
|
||||
NOINSTRUCTION echo ba
|
||||
|
||||
CMD ["/bin/init"]
|
||||
`, true)
|
||||
c.Assert(err.Error(), checker.Contains, "Dockerfile parse error line 6: Unknown instruction: NOINSTRUCTION")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildLineErrorWithComments(c *check.C) {
|
||||
name := "test_build_line_error_with_comments"
|
||||
|
||||
_, err := buildImage(name,
|
||||
`FROM busybox
|
||||
# This will print hello world
|
||||
# and then ba
|
||||
RUN echo hello world
|
||||
RUM echo ba
|
||||
`, true)
|
||||
c.Assert(err.Error(), checker.Contains, "Dockerfile parse error line 5: Unknown instruction: RUM")
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue