[Console] Show code when an exception is thrown#17504
Conversation
There was a problem hiding this comment.
I propose to change 2 things here:
-
Use
0 !== $codeinstead of$code > 0, just anything that's not the default value should be printed imo -
Use just one sprintf call:
$title = sprintf(' [%s%s]', get_class($e), $output->isVerbose() && ($code = $e->getCode()) ? ' - code '.$code : '')
|
I like the idea. Maybe the format should be changed to |
|
Thank you for your feedback @wouterj, I did changes. No ? |
There was a problem hiding this comment.
This condition should be in yoda style:
0 !== ($code = $e->getCode())
|
@maidmaid good idea 👍 Could you also add a test for that please? ref: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Tests/ApplicationTest.php |
|
Thank you @mheki, I done tests but I don't understand why it fail... |
|
@maidmaid not related to your changes. We have a bug in our testsuite. |
|
@stof thank you for this information. Maybe list the errors can help you a little bit :
Only on Travis PHP 5.6. |
|
Thank you @maidmaid. |
…aid) This PR was squashed before being merged into the 3.1-dev branch (closes #17504). Discussion ---------- [Console] Show code when an exception is thrown | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Hi ! When an exception is thrown, sf console doesn't show the code exception, while this code is very useful during developpement (for example, [guzzle put http status code in his code exception](https://github.com/guzzle/guzzle/blob/6.1.1/src/Exception/RequestException.php#L30-L33)). I propose you that we show the code exception only when the code exception > 0 and with ``-v`` verbosity. It means : - ``throw new Exception('Not found', 0)`` with normal verbosity --> no change - ``throw new Exception('Not found', 0)`` with ``-v`` verbosity --> no change - ``throw new Exception('Not found', 404)`` with normal verbosity --> no change - **but** ``throw new Exception('Not found', 404)`` with ``-v`` verbosity --> showing :  Commits ------- f8cd9e8 [Console] Show code when an exception is thrown
Hi !
When an exception is thrown, sf console doesn't show the code exception, while this code is very useful during developpement (for example, guzzle put http status code in his code exception).
I propose you that we show the code exception only when the code exception > 0 and with
-vverbosity. It means :throw new Exception('Not found', 0)with normal verbosity --> no changethrow new Exception('Not found', 0)with-vverbosity --> no changethrow new Exception('Not found', 404)with normal verbosity --> no changethrow new Exception('Not found', 404)with-vverbosity --> showing :