-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Show code when an exception is thrown #17504
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
$title = $output->isVerbose() && ($code = $e->getCode()) > 0 | ||
? sprintf(' [%s - code %s] ', get_class($e), $code) | ||
: sprintf(' [%s] ', get_class($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.
I propose to change 2 things here:
-
Use
0 !== $code
instead 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 ? |
$title = sprintf( | ||
' [%s%s] ', | ||
get_class($e), | ||
$output->isVerbose() && ($code = $e->getCode()) !== 0 ? ' ('.$code.')' : '' |
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 condition should be in yoda style:
0 !== ($code = $e->getCode())
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 are right @paradajozsef, it's done.
@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
-v
verbosity. It means :throw new Exception('Not found', 0)
with normal verbosity --> no changethrow new Exception('Not found', 0)
with-v
verbosity --> no changethrow new Exception('Not found', 404)
with normal verbosity --> no changethrow new Exception('Not found', 404)
with-v
verbosity --> showing :