Browse code

Specify in which line the Dockerfile parser failed

Signed-off-by: Boaz Shuster <ripcurld.github@gmail.com>

Boaz Shuster authored on 2017/01/11 08:36:08
Showing 2 changed files
... ...
@@ -264,7 +264,7 @@ func (b *Builder) build(stdout io.Writer, stderr io.Writer, out io.Writer) (stri
264 264
 	total := len(b.dockerfile.Children)
265 265
 	for _, n := range b.dockerfile.Children {
266 266
 		if err := b.checkDispatch(n, false); err != nil {
267
-			return "", err
267
+			return "", perrors.Wrapf(err, "Dockerfile parse error line %d", n.StartLine)
268 268
 		}
269 269
 	}
270 270
 
... ...
@@ -7405,3 +7405,55 @@ func (s *DockerSuite) TestBuildWorkdirCmd(c *check.C) {
7405 7405
 	c.Assert(err, checker.IsNil)
7406 7406
 	c.Assert(strings.Count(out, "Using cache"), checker.Equals, 1)
7407 7407
 }
7408
+
7409
+func (s *DockerSuite) TestBuildLineErrorOnBuild(c *check.C) {
7410
+	name := "test_build_line_error_onbuild"
7411
+
7412
+	_, err := buildImage(name,
7413
+		`FROM busybox
7414
+  ONBUILD
7415
+  `, true)
7416
+	c.Assert(err.Error(), checker.Contains, "Dockerfile parse error line 2: ONBUILD requires at least one argument")
7417
+}
7418
+
7419
+func (s *DockerSuite) TestBuildLineErrorUknownInstruction(c *check.C) {
7420
+	name := "test_build_line_error_unknown_instruction"
7421
+
7422
+	_, err := buildImage(name,
7423
+		`FROM busybox
7424
+  RUN echo hello world
7425
+  NOINSTRUCTION echo ba
7426
+  RUN echo hello
7427
+  ERROR
7428
+  `, true)
7429
+	c.Assert(err.Error(), checker.Contains, "Dockerfile parse error line 3: Unknown instruction: NOINSTRUCTION")
7430
+}
7431
+
7432
+func (s *DockerSuite) TestBuildLineErrorWithEmptyLines(c *check.C) {
7433
+	name := "test_build_line_error_with_empty_lines"
7434
+
7435
+	_, err := buildImage(name,
7436
+		`
7437
+  FROM busybox
7438
+
7439
+  RUN echo hello world
7440
+
7441
+  NOINSTRUCTION echo ba
7442
+
7443
+  CMD ["/bin/init"]
7444
+  `, true)
7445
+	c.Assert(err.Error(), checker.Contains, "Dockerfile parse error line 6: Unknown instruction: NOINSTRUCTION")
7446
+}
7447
+
7448
+func (s *DockerSuite) TestBuildLineErrorWithComments(c *check.C) {
7449
+	name := "test_build_line_error_with_comments"
7450
+
7451
+	_, err := buildImage(name,
7452
+		`FROM busybox
7453
+  # This will print hello world
7454
+  # and then ba
7455
+  RUN echo hello world
7456
+  RUM echo ba
7457
+  `, true)
7458
+	c.Assert(err.Error(), checker.Contains, "Dockerfile parse error line 5: Unknown instruction: RUM")
7459
+}