Browse code

Improve error message for COPY missing destination

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2017/09/21 23:03:59
Showing 2 changed files
... ...
@@ -235,7 +235,7 @@ func parseLabel(req parseRequest) (*LabelCommand, error) {
235 235
 
236 236
 func parseAdd(req parseRequest) (*AddCommand, error) {
237 237
 	if len(req.args) < 2 {
238
-		return nil, errAtLeastTwoArguments("ADD")
238
+		return nil, errNoDestinationArgument("ADD")
239 239
 	}
240 240
 	flChown := req.flags.AddString("chown", "")
241 241
 	if err := req.flags.Parse(); err != nil {
... ...
@@ -250,7 +250,7 @@ func parseAdd(req parseRequest) (*AddCommand, error) {
250 250
 
251 251
 func parseCopy(req parseRequest) (*CopyCommand, error) {
252 252
 	if len(req.args) < 2 {
253
-		return nil, errAtLeastTwoArguments("COPY")
253
+		return nil, errNoDestinationArgument("COPY")
254 254
 	}
255 255
 	flChown := req.flags.AddString("chown", "")
256 256
 	flFrom := req.flags.AddString("from", "")
... ...
@@ -622,8 +622,8 @@ func errExactlyOneArgument(command string) error {
622 622
 	return errors.Errorf("%s requires exactly one argument", command)
623 623
 }
624 624
 
625
-func errAtLeastTwoArguments(command string) error {
626
-	return errors.Errorf("%s requires at least two arguments", command)
625
+func errNoDestinationArgument(command string) error {
626
+	return errors.Errorf("%s requires at least two arguments, but only one was provided. Destination could not be determined.", command)
627 627
 }
628 628
 
629 629
 func errBlankCommandNames(command string) error {
... ...
@@ -45,7 +45,7 @@ func TestCommandsAtLeastOneArgument(t *testing.T) {
45 45
 	}
46 46
 }
47 47
 
48
-func TestCommandsAtLeastTwoArgument(t *testing.T) {
48
+func TestCommandsNoDestinationArgument(t *testing.T) {
49 49
 	commands := []string{
50 50
 		"ADD",
51 51
 		"COPY",
... ...
@@ -55,7 +55,7 @@ func TestCommandsAtLeastTwoArgument(t *testing.T) {
55 55
 		ast, err := parser.Parse(strings.NewReader(command + " arg1"))
56 56
 		require.NoError(t, err)
57 57
 		_, err = ParseInstruction(ast.AST.Children[0])
58
-		assert.EqualError(t, err, errAtLeastTwoArguments(command).Error())
58
+		assert.EqualError(t, err, errNoDestinationArgument(command).Error())
59 59
 	}
60 60
 }
61 61