More helpful error message when not sufficiently argumentative
The error message suggests you need one argument even when you have provided one. Suggest having another argument. Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
parent
2684459ed4
commit
4ce93940b7
3 changed files with 27 additions and 5 deletions
|
@ -155,7 +155,7 @@ func label(b *Builder, args []string, attributes map[string]bool, original strin
|
|||
//
|
||||
func add(b *Builder, args []string, attributes map[string]bool, original string) error {
|
||||
if len(args) < 2 {
|
||||
return errAtLeastOneArgument("ADD")
|
||||
return errAtLeastTwoArguments("ADD")
|
||||
}
|
||||
|
||||
if err := b.flags.Parse(); err != nil {
|
||||
|
@ -171,7 +171,7 @@ func add(b *Builder, args []string, attributes map[string]bool, original string)
|
|||
//
|
||||
func dispatchCopy(b *Builder, args []string, attributes map[string]bool, original string) error {
|
||||
if len(args) < 2 {
|
||||
return errAtLeastOneArgument("COPY")
|
||||
return errAtLeastTwoArguments("COPY")
|
||||
}
|
||||
|
||||
if err := b.flags.Parse(); err != nil {
|
||||
|
@ -760,6 +760,10 @@ func errExactlyOneArgument(command string) error {
|
|||
return fmt.Errorf("%s requires exactly one argument", command)
|
||||
}
|
||||
|
||||
func errAtLeastTwoArguments(command string) error {
|
||||
return fmt.Errorf("%s requires at least two arguments", command)
|
||||
}
|
||||
|
||||
func errTooManyArguments(command string) error {
|
||||
return fmt.Errorf("Bad input to %s, too many arguments", command)
|
||||
}
|
||||
|
|
|
@ -43,8 +43,6 @@ func TestCommandsAtLeastOneArgument(t *testing.T) {
|
|||
commands := []commandWithFunction{
|
||||
{"ENV", func(args []string) error { return env(nil, args, nil, "") }},
|
||||
{"LABEL", func(args []string) error { return label(nil, args, nil, "") }},
|
||||
{"ADD", func(args []string) error { return add(nil, args, nil, "") }},
|
||||
{"COPY", func(args []string) error { return dispatchCopy(nil, args, nil, "") }},
|
||||
{"ONBUILD", func(args []string) error { return onbuild(nil, args, nil, "") }},
|
||||
{"EXPOSE", func(args []string) error { return expose(nil, args, nil, "") }},
|
||||
{"VOLUME", func(args []string) error { return volume(nil, args, nil, "") }}}
|
||||
|
@ -64,6 +62,26 @@ func TestCommandsAtLeastOneArgument(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestCommandsAtLeastTwoArguments(t *testing.T) {
|
||||
commands := []commandWithFunction{
|
||||
{"ADD", func(args []string) error { return add(nil, args, nil, "") }},
|
||||
{"COPY", func(args []string) error { return dispatchCopy(nil, args, nil, "") }}}
|
||||
|
||||
for _, command := range commands {
|
||||
err := command.function([]string{"arg1"})
|
||||
|
||||
if err == nil {
|
||||
t.Fatalf("Error should be present for %s command", command.name)
|
||||
}
|
||||
|
||||
expectedError := fmt.Sprintf("%s requires at least two arguments", command.name)
|
||||
|
||||
if err.Error() != expectedError {
|
||||
t.Fatalf("Wrong error message for %s. Got: %s. Should be: %s", command.name, err.Error(), expectedError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommandsTooManyArguments(t *testing.T) {
|
||||
commands := []commandWithFunction{
|
||||
{"ENV", func(args []string) error { return env(nil, args, nil, "") }},
|
||||
|
|
|
@ -28,7 +28,7 @@ func initDispatchTestCases() []dispatchTestCase {
|
|||
dockerfile: `COPY
|
||||
quux \
|
||||
bar`,
|
||||
expectedError: "COPY requires at least one argument",
|
||||
expectedError: "COPY requires at least two arguments",
|
||||
},
|
||||
{
|
||||
name: "ONBUILD forbidden FROM",
|
||||
|
|
Loading…
Reference in a new issue