builder: handle anything we cannot parse the command for as a fatal error
| ... | ... |
@@ -72,7 +72,10 @@ func parseLine(line string) (string, *Node, error) {
|
| 72 | 72 |
return line, nil, nil |
| 73 | 73 |
} |
| 74 | 74 |
|
| 75 |
- cmd, args := splitCommand(line) |
|
| 75 |
+ cmd, args, err := splitCommand(line) |
|
| 76 |
+ if err != nil {
|
|
| 77 |
+ return "", nil, err |
|
| 78 |
+ } |
|
| 76 | 79 |
|
| 77 | 80 |
node := &Node{}
|
| 78 | 81 |
node.Value = cmd |
| ... | ... |
@@ -1,6 +1,9 @@ |
| 1 | 1 |
package parser |
| 2 | 2 |
|
| 3 |
-import "strings" |
|
| 3 |
+import ( |
|
| 4 |
+ "fmt" |
|
| 5 |
+ "strings" |
|
| 6 |
+) |
|
| 4 | 7 |
|
| 5 | 8 |
// QuoteString walks characters (after trimming), escapes any quotes and |
| 6 | 9 |
// escapes, then wraps the whole thing in quotes. Very useful for generating |
| ... | ... |
@@ -66,12 +69,17 @@ func fullDispatch(cmd, args string) (*Node, map[string]bool, error) {
|
| 66 | 66 |
|
| 67 | 67 |
// splitCommand takes a single line of text and parses out the cmd and args, |
| 68 | 68 |
// which are used for dispatching to more exact parsing functions. |
| 69 |
-func splitCommand(line string) (string, string) {
|
|
| 69 |
+func splitCommand(line string) (string, string, error) {
|
|
| 70 | 70 |
cmdline := TOKEN_WHITESPACE.Split(line, 2) |
| 71 |
+ |
|
| 72 |
+ if len(cmdline) != 2 {
|
|
| 73 |
+ return "", "", fmt.Errorf("We do not understand this file. Please ensure it is a valid Dockerfile. Parser error at %q", line)
|
|
| 74 |
+ } |
|
| 75 |
+ |
|
| 71 | 76 |
cmd := strings.ToLower(cmdline[0]) |
| 72 | 77 |
// the cmd should never have whitespace, but it's possible for the args to |
| 73 | 78 |
// have trailing whitespace. |
| 74 |
- return cmd, strings.TrimSpace(cmdline[1]) |
|
| 79 |
+ return cmd, strings.TrimSpace(cmdline[1]), nil |
|
| 75 | 80 |
} |
| 76 | 81 |
|
| 77 | 82 |
// covers comments and empty lines. Lines should be trimmed before passing to |