-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] [Console][DX] add a warning when command is not found #26290
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
[FrameworkBundle] [Console][DX] add a warning when command is not found #26290
Conversation
52a9c9c
to
dcfa734
Compare
Qualifies as a bug since an exception was thrown before 3.4, breaking the whole console with a clear stack trace, currently you have no information at all. |
throw new CommandNotRegisteredException(implode(' | ||
', $errors), 0, $e); | ||
} | ||
throw $e; |
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.
IMO we should just call renderRegistrationErrors()
before callingfind()
.
We can’t do that because of input and ouput we don’t have them
Le ven. 23 févr. 2018 à 20:08, Robin Chalas <notifications@github.com> a
écrit :
… ***@***.**** commented on this pull request.
------------------------------
In src/Symfony/Bundle/FrameworkBundle/Console/Application.php
<#26290 (comment)>:
> @@ -91,7 +93,18 @@ public function find($name)
{
$this->registerCommands();
- return parent::find($name);
+ try {
+ return parent::find($name);
+ } catch (CommandNotFoundException $e) {
+ if ($this->registrationErrors) {
+ foreach ($this->registrationErrors as $error) {
+ $errors[] = $error->getMessage();
+ }
+ throw new CommandNotRegisteredException(implode('
+ ', $errors), 0, $e);
+ }
+ throw $e;
IMO we should just call renderRegistrationErrors() before callingfind().
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#26290 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADSq8rH-L4mX5Tdfb4REbJKzvxDsO0b_ks5tXwy5gaJpZM4SRR46>
.
|
if i get this right, wrapping the public function doRun(...)
{
// ...
try {
return parent::doRun($input, $output);
} catch (CommandNotFoundException $e) {
if ($this->registrationErrors) {
$this->renderRegistrationErrors($input, $output);
}
throw $e;
}
} |
Thanks @chr-hertel ! it's clearly better than what I thought. |
e24222f
to
0f93cbd
Compare
return parent::find($name); | ||
try { | ||
return parent::find($name); | ||
} catch (CommandNotFoundException $e) { |
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.
this is not needed anymore when catching in doRun(...)
, is it?
0f93cbd
to
ecefeec
Compare
} | ||
|
||
throw $e; | ||
} |
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.
instead we can just call $this->registerCommands()
before the if
above
$container = new ContainerBuilder(); | ||
$container->register('event_dispatcher', EventDispatcher::class); | ||
$container->register(ThrowingCommand::class, ThrowingCommand::class); | ||
$container->setParameter('console.command.ids', array(ThrowingCommand::class => ThrowingCommand::class)); |
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 throwing
command is not necessary for this test
@@ -165,6 +165,37 @@ public function testRunOnlyWarnsOnUnregistrableCommand() | ||
$this->assertContains('fine', $output); | ||
} | ||
|
||
public function testRunOnlyWarnsOnNoName() |
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.
testRegistrationErrorsAreDisplayedOnCommandNotFound
$this->assertSame(1, $tester->getStatusCode()); | ||
$this->assertContains('Some commands could not be registered:', $output); | ||
$this->assertContains('throwing', $output); | ||
$this->assertContains('fine', $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.
Command "fine" is not defined.
|
||
$tester = new ApplicationTester($application); | ||
$tester->run(array('command' => 'fine')); | ||
$tester->getOutput(); |
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.
to revert
$message = sprintf("[WARNING] Some commands could not be registered: \n %s", $message); | ||
parent::__construct($message, $previous instanceof CommandNotFoundException ? $previous->getAlternatives() : array(), $code, $previous); | ||
} | ||
} |
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.
not needed anymore
c26aa09
to
84940c5
Compare
84940c5
to
efd8f7f
Compare
Status: Needs Review |
Thank you @Simperfit. |
… is not found (Simperfit) This PR was merged into the 3.4 branch. Discussion ---------- [FrameworkBundle] [Console][DX] add a warning when command is not found | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- don't forget to update UPGRADE-*.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | none | License | MIT | Doc PR | This PR add DX on the the console `find()` and `get()` methods when a command is not found because it has not been registered properly. Commits ------- efd8f7f [FrameworkBundle] [Console] add a warning when command is not found
This PR add DX on the the console
find()
andget()
methods when a command is not found because it has not been registered properly.