From 05661f733925f91a379ca1d135483f9e0793e798 Mon Sep 17 00:00:00 2001 From: Dany Maillard Date: Sat, 23 Jan 2016 15:16:18 +0100 Subject: [PATCH 1/4] Show code when an exception is thrown --- src/Symfony/Component/Console/Application.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 41c6657e0862a..fad41d5541c75 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -588,7 +588,10 @@ public function renderException(\Exception $e, OutputInterface $output) $output->writeln('', OutputInterface::VERBOSITY_QUIET); do { - $title = sprintf(' [%s] ', get_class($e)); + $title = $output->isVerbose() && ($code = $e->getCode()) > 0 + ? sprintf(' [%s - code %s] ', get_class($e), $code) + : sprintf(' [%s] ', get_class($e)) + ; $len = $this->stringWidth($title); From 7f498189e5a1a9e2d87ac4341788f30fb7f4a441 Mon Sep 17 00:00:00 2001 From: Dany Maillard Date: Sun, 24 Jan 2016 12:02:55 +0100 Subject: [PATCH 2/4] Change code condition, sprintf call and code format --- src/Symfony/Component/Console/Application.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index fad41d5541c75..4577c8fb97c34 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -588,10 +588,11 @@ public function renderException(\Exception $e, OutputInterface $output) $output->writeln('', OutputInterface::VERBOSITY_QUIET); do { - $title = $output->isVerbose() && ($code = $e->getCode()) > 0 - ? sprintf(' [%s - code %s] ', get_class($e), $code) - : sprintf(' [%s] ', get_class($e)) - ; + $title = sprintf( + ' [%s%s] ', + get_class($e), + $output->isVerbose() && ($code = $e->getCode()) !== 0 ? ' ('.$code.')' : '' + ); $len = $this->stringWidth($title); From 6612f482fce5019c0d3904df382d63e4d6e4cb7e Mon Sep 17 00:00:00 2001 From: Dany Maillard Date: Sun, 24 Jan 2016 20:54:27 +0100 Subject: [PATCH 3/4] Use yoda notation --- src/Symfony/Component/Console/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 4577c8fb97c34..5f186d3f0d6b8 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -591,7 +591,7 @@ public function renderException(\Exception $e, OutputInterface $output) $title = sprintf( ' [%s%s] ', get_class($e), - $output->isVerbose() && ($code = $e->getCode()) !== 0 ? ' ('.$code.')' : '' + $output->isVerbose() && 0 !== ($code = $e->getCode()) ? ' ('.$code.')' : '' ); $len = $this->stringWidth($title); From cfa3421bb892a2435661e10aebc788c76e6fd397 Mon Sep 17 00:00:00 2001 From: Dany Maillard Date: Tue, 26 Jan 2016 22:54:06 +0100 Subject: [PATCH 4/4] Add tests --- src/Symfony/Component/Console/Tests/ApplicationTest.php | 5 +++++ src/Symfony/Component/Console/Tests/Fixtures/Foo3Command.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index 7eaa28d40d577..b44a00ae6b17a 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -520,6 +520,11 @@ public function testRenderException() $tester->run(array('command' => 'foo3:bar'), array('decorated' => false)); $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3.txt', $tester->getDisplay(true), '->renderException() renders a pretty exceptions with previous exceptions'); + $tester->run(array('command' => 'foo3:bar'), array('decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE)); + $this->assertRegExp('/\[Exception\]\s*First exception/', $tester->getDisplay(), '->renderException() renders a pretty exception without code exception when code exception is default and verbosity is verbose'); + $this->assertRegExp('/\[Exception\]\s*Second exception/', $tester->getDisplay(), '->renderException() renders a pretty exception without code exception when code exception is 0 and verbosity is verbose'); + $this->assertRegExp('/\[Exception \(404\)\]\s*Third exception/', $tester->getDisplay(), '->renderException() renders a pretty exception with code exception when code exception is 404 and verbosity is verbose'); + $tester->run(array('command' => 'foo3:bar'), array('decorated' => true)); $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3decorated.txt', $tester->getDisplay(true), '->renderException() renders a pretty exceptions with previous exceptions'); diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Foo3Command.php b/src/Symfony/Component/Console/Tests/Fixtures/Foo3Command.php index 6c890fafff619..adb3a2d809f71 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Foo3Command.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Foo3Command.php @@ -23,7 +23,7 @@ protected function execute(InputInterface $input, OutputInterface $output) throw new \Exception('Second exception comment', 0, $e); } } catch (\Exception $e) { - throw new \Exception('Third exception comment', 0, $e); + throw new \Exception('Third exception comment', 404, $e); } } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy