Skip to content

[Console] Too many arguments message contains an incorrect number of missing arguments #38904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aadmathijssen opened this issue Oct 30, 2020 · 4 comments · Fixed by #38919
Closed

Comments

@aadmathijssen
Copy link

Symfony version(s) affected: 5.1.8 (and earlier)

Description

Whenever a Symfony Console command is called with too many arguments, a "Too many arguments" error is shown on the CLI. This message also states which arguments are expected. But this message always contains "command" as an extra argument. This can be confusing for the user, as the reported number of arguments is one off with what it should be.

How to reproduce

Install the Symfony skeleton and run the following command:

bin/console secrets:list foo

It shows the following message:

Too many arguments, expected arguments "command".

This is incorrect, as the command itself expects no arguments at all.

Similarly, the command

bin/console secrets:set foo bar baz

shows the message:

Too many arguments, expected arguments "command" "name" "file".

Here I would have expected a message stating that that "name" and "file" are the expected arguments, but not "command".

Possible Solution

The message is thrown on line 139 of src/Symfony/Component/Console/Input/ArgvInput.php.

Here it can be seen that keys of the $this->definition->getArguments() array are printed.

The simplest solution to fix this seems to remove the first key of the array when creating the exception message.

@Nyholm
Copy link
Member

Nyholm commented Oct 30, 2020

Hm.. I think there is a terminology confusion here.

The actual command/program/binary you are running is bin/console. The first argument to that command is "symfony-command-name", (ie a cli name of a class extending Command).

When you are running:

bin/console secrets:list foo

It is the bin/console command/program/binary that says: "Hey, too many arguments, Im only expecting a symfony-command-name."

Does it make more sense?

@aadmathijssen
Copy link
Author

Well, I think the problem is that the contents of the error message depend on the command that is used. More precisely, the names of the actual expected arguments (except from "command") only make sense for the command that was supplied.

So I think it is better to formulate the exception in the context of the command that is used, i.e. use something like

Too many arguments supplied for this command, expected "name" "file".

instead of

Too many arguments, expected arguments "command" "name" "file".

@Nyholm
Copy link
Member

Nyholm commented Oct 30, 2020

Yeah. I can agree with that. Or even better:

Too many arguments supplied for “acme:foobar” command, expected "name" "file".

@aadmathijssen
Copy link
Author

Yes that's even better. Thanks for the PR, @Nyholm!

@xabbuh xabbuh added the Console label Nov 1, 2020
@fabpot fabpot closed this as completed Nov 1, 2020
fabpot added a commit that referenced this issue Nov 1, 2020
This PR was squashed before being merged into the 5.2-dev branch.

Discussion
----------

[Console] Make error message more verbose

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #38904
| License       | MIT
| Doc PR        | no

This will make the error message a bit more verbose when you are using too many or too few arguments.

Commits
-------

ef221e8 [Console] Make error message more verbose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants