Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Console] Fix input validation when required arguments are missing#15533
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
jakzal commentedAug 13, 2015
If I used a foreach loop instead of array_filter, I could improve the exception message and say 'Not enough arguments. "name" is missing.'. What do you think? |
jakzal commentedAug 13, 2015
This broke tests in FrameworkBundle. Looking into this. |
nochso commentedAug 13, 2015
I had a look at the tests for HelpCommand:
What is passed as arguments: HelpCommand has no required arguments:
However, the |
marek-pietrzak-tg commentedAug 16, 2015
I had a quick look at these failing tests as well. |
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.
if (count($requiredArguments) < $definition->getArgumentRequiredCount()) { would be shorter
fabpot commentedSep 14, 2015
@jakzal Any news on this one? And to answer your question, I would indeed give more information in the error message if possible. |
Previous rule was only working when arguments are passed from command line, as in command line there is no way of skipping an argument. The rule does not work for arguments set on the Input after a command is run.
30cbe80 tof12a4c1Comparejakzal commentedSep 14, 2015
I added a better exception message: Solving the problem with failing command tests is a bit more complex. The The previous version of To fix this we need to either:
First solution would break lots of existing command tests, and the second doesn't seem like the right place (as the command argument is added by the application). |
jakzal commentedSep 15, 2015
I went with option 2. Happy to receive feedback. Ping @symfony/deciders. |
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.
Can you explain when this happens? I think it deserves a comment.
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.
Great suggestion. I'll add:
// The command name argument is often omitted when a command is executed directly with its run() method.// It will fail the validation since the command argument is required by the application.
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.
Writing this comment gave me another idea: is the command argument really a required argument? What if we made it optional instead of setting it here?
f2145bd to45c1cc6Compare45c1cc6 to4982b02Comparefabpot commentedSep 16, 2015
👍 |
1 similar comment
weaverryan commentedSep 26, 2015
👍 |
xabbuh commentedSep 27, 2015
@jakzal Usually, when using the |
jakzal commentedSep 27, 2015
@xabbuh that's not gonna fix the case of calling commands directly, like here:https://github.com/symfony/symfony/blob/2.3/src/Symfony/Bundle/FrameworkBundle/Command/RouterMatchCommand.php#L83-83 |
xabbuh commentedSep 27, 2015
Hm, indeed. 👍 Status: Reviewed |
fabpot commentedSep 27, 2015
Thank you@jakzal. |
… missing (jakzal)This PR was merged into the 2.3 branch.Discussion----------[Console] Fix input validation when required arguments are missing| Q | A| ------------- | ---| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#15505| License | MIT| Doc PR | -The rule that was here in place previously only works when arguments are passed from command line, as in command line there is no way of skipping an argument. The rule does not work for arguments set on the Input after a command is run.Commits-------4982b02 [Console] Add the command name to input arguments if it's missingf12a4c1 [Console] Fix input validation when required arguments are missing
This makes test pass again given the improvements to the message of theexception that is thrown sincesymfony/symfony#15533 when a requiredargument is missing.
The rule that was here in place previously only works when arguments are passed from command line, as in command line there is no way of skipping an argument. The rule does not work for arguments set on the Input after a command is run.