Skip to content

[Console] Allow to catch CommandNotFoundException #22181

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
Apr 5, 2017

Conversation

chalasr
Copy link
Member

@chalasr chalasr commented Mar 27, 2017

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #22144 (comment)
License MIT
Doc PR n/a

Basically reverts #22144, making the command argument optional in console.error event instead, so that CommandNotFoundException can be handled as any other console error.

@@ -27,7 +27,7 @@ class ConsoleErrorEvent extends ConsoleExceptionEvent
private $error;
private $handled = false;

public function __construct(Command $command, InputInterface $input, OutputInterface $output, $error, $exitCode)
public function __construct(Command $command = null, InputInterface $input, OutputInterface $output, $error, $exitCode)
Copy link
Member

Choose a reason for hiding this comment

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

It's always weird to have optional argument before required one. Could we do something for that ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, arguments have been reordered

@chalasr chalasr force-pushed the cmd-not-found-listener branch 4 times, most recently from 2337015 to 0ff0123 Compare March 27, 2017 17:37
@nicolas-grekas nicolas-grekas added this to the 3.3 milestone Mar 28, 2017
@chalasr
Copy link
Member Author

chalasr commented Mar 29, 2017

ping @wouterj

$exception = $exitCode;
$exitCode = $tmpExitCode;

@trigger_error(sprintf('Passing an instance of %s as first argument of %s() is deprecated since version 3.3. Pass it as 5th argument instead.', Command::class, __METHOD__), E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

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

This deprecation is useless imo. People creating the class as ($command, $input, $output) already get a deprecation, as the class shouldn't be initialized (ConsoleErrorEvent should be initialized instead).

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, deprecation removed.

@chalasr chalasr force-pushed the cmd-not-found-listener branch 3 times, most recently from fc50aef to ca50cf9 Compare March 29, 2017 16:28
@@ -27,12 +25,21 @@ class ConsoleExceptionEvent extends ConsoleEvent
private $exception;
private $exitCode;

public function __construct(Command $command, InputInterface $input, OutputInterface $output, \Exception $exception, $exitCode, $deprecation = true)
public function __construct($input, $output, $exception, $exitCode, $command = null, $deprecation = true)
Copy link
Member

Choose a reason for hiding this comment

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

Given that the class is deprecated anyway I would just allow $command to be null instead of shifting constructor arguments.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, I wasn't sure. Fixed.

@chalasr chalasr force-pushed the cmd-not-found-listener branch from ca50cf9 to b21ce85 Compare March 29, 2017 19:37
@chalasr
Copy link
Member Author

chalasr commented Mar 30, 2017

Ready, build failure unrelated.

@chalasr
Copy link
Member Author

chalasr commented Apr 5, 2017

Bump, it will be harder to make this change after 3.3 (would involve deprecations).

@fabpot
Copy link
Member

fabpot commented Apr 5, 2017

Thank you @chalasr.

@fabpot fabpot merged commit b21ce85 into symfony:master Apr 5, 2017
fabpot added a commit that referenced this pull request Apr 5, 2017
…lasr)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[Console] Allow to catch CommandNotFoundException

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #22144 (comment)
| License       | MIT
| Doc PR        | n/a

Basically reverts #22144, making the command argument optional in console.error event instead, so that `CommandNotFoundException` can be handled as any other console error.

Commits
-------

b21ce85 [Console] Allow to catch CommandNotFoundException
@chalasr chalasr deleted the cmd-not-found-listener branch April 5, 2017 17:08
@fabpot fabpot mentioned this pull request May 1, 2017
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.

7 participants