Skip to content

Commit eff73bd

Browse files
author
Robin Chalas
committed
feature symfony#24131 [Console] Do not display short exception trace for common console exceptions (yceruto)
This PR was merged into the 3.4 branch. Discussion ---------- [Console] Do not display short exception trace for common console exceptions | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - ![console_before](https://user-images.githubusercontent.com/2028198/30173516-edb9e42c-93c5-11e7-882e-f8b0335387b3.png) I'd like reconsider [the new error output][1] with short exception trace always displayed at top, IMHO it's annoying for common exceptions (there is not real debugging reason, the message is clear enough) such as `Symfony\Component\Console\Exception\*` which have an impact into current CLI applications. However, I'm proposing display it for unexpected exceptions or if verbosity is enabled: ![console](https://user-images.githubusercontent.com/2028198/30173085-94322636-93c4-11e7-81a6-bba807910e62.png) Note @nicolas-grekas's symfony#21414 (comment) is still covered. [1]: symfony#21414 Commits ------- 47b1106 Do not display short exception trace for built-in console exceptions
2 parents c97c6d4 + 47b1106 commit eff73bd

File tree

4 files changed

+3
-4
lines changed

4 files changed

+3
-4
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,9 @@ protected function doRenderException(\Exception $e, OutputInterface $output)
761761
}
762762

763763
$messages = array();
764-
$messages[] = sprintf('<comment>%s</comment>', OutputFormatter::escape(sprintf('In %s line %s:', basename($e->getFile()) ?: 'n/a', $e->getLine() ?: 'n/a')));
764+
if (!$e instanceof ExceptionInterface || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
765+
$messages[] = sprintf('<comment>%s</comment>', OutputFormatter::escape(sprintf('In %s line %s:', basename($e->getFile()) ?: 'n/a', $e->getLine() ?: 'n/a')));
766+
}
765767
$messages[] = $emptyLine = sprintf('<error>%s</error>', str_repeat(' ', $len));
766768
if ('' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
767769
$messages[] = sprintf('<error>%s%s</error>', $title, str_repeat(' ', max(0, $len - Helper::strlen($title))));

src/Symfony/Component/Console/Tests/Fixtures/application_renderexception1.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
In Application.php line 615:
32

43
Command "foo" is not defined.
54

src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
In ArrayInput.php line 178:
32

43
The "--foo" option does not exist.
54

src/Symfony/Component/Console/Tests/Fixtures/application_renderexception4.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
In Application.php line 615:
32

43
Command "foo" is not define
54
d.

0 commit comments

Comments
 (0)