-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
@@ -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; |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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".
be44cfa
to
ef221e8
Compare
Thank you @Nyholm. |
Thank you for all reviews and for merging. |
This will make the error message a bit more verbose when you are using too many or too few arguments.