Skip to content

[Console] Make error message more verbose #38919

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

Merged
merged 1 commit into from
Nov 1, 2020

Conversation

Nyholm
Copy link
Member

@Nyholm Nyholm commented Oct 31, 2020

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.

@@ -165,11 +165,25 @@ private function parseArgument(string $token)
// unexpected argument
} else {
$all = $this->definition->getArguments();
$symfonyCommandName = null;
if (($inputArgument = $all[$key = array_key_first($all)] ?? null) && 'command' === $inputArgument->getName()) {
$symfonyCommandName = $this->tokens[0] ?? null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, what if people use short command name ? like d:m:m instead of doctrine: migration:migrate
Just wondering what should be the output...

Copy link
Member Author

@Nyholm Nyholm Oct 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. The output would be:

Too many arguments to "d:m:m" command, expected arguments "version".  

@@ -165,11 +165,25 @@ private function parseArgument(string $token)
// unexpected argument
} else {
$all = $this->definition->getArguments();
$symfonyCommandName = null;
if (($inputArgument = $all[$key = array_key_first($all)] ?? null) && 'command' === $inputArgument->getName()) {
$symfonyCommandName = $this->tokens[0] ?? null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command name is not always $this->tokens[0]. bin/console -v secrets:list will have -v as $this->tokens[0]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use $this->arguments['command'][0] instead (when we reach this error, we know that the command argument has already been parsed)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome.
You are correct. I've updated the PR.

❯ bin/console -v secrets:list foobar

In ArgvInput.php line 186:
                                                                   
  [Symfony\Component\Console\Exception\RuntimeException]           
  No arguments expected for "secrets:list" command, got "foobar".  

@fabpot fabpot force-pushed the console-error-arguments branch from be44cfa to ef221e8 Compare November 1, 2020 17:40
@fabpot
Copy link
Member

fabpot commented Nov 1, 2020

Thank you @Nyholm.

@Nyholm
Copy link
Member Author

Nyholm commented Nov 1, 2020

Thank you for all reviews and for merging.

@Nyholm Nyholm deleted the console-error-arguments branch November 1, 2020 17:43
@fabpot fabpot mentioned this pull request Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Console] Too many arguments message contains an incorrect number of missing arguments
7 participants