8000 [Console] Move back root exception to stack trace in verbose mode · symfony/symfony@fbe2bf8 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit fbe2bf8

Browse files
author
Robin Chalas
committed
[Console] Move back root exception to stack trace in verbose mode
1 parent 227cf2c commit fbe2bf8

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ protected function doRenderException(\Exception $e, OutputInterface $output)
780780
}
781781

782782
$messages = array();
783-
if (!$e instanceof ExceptionInterface || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
783+
if (!$e instanceof ExceptionInterface && OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) {
784784
$messages[] = sprintf('<comment>%s</comment>', OutputFormatter::escape(sprintf('In %s line %s:', basename($e->getFile()) ?: 'n/a', $e->getLine() ?: 'n/a')));
785785
}
786786
$messages[] = $emptyLine = sprintf('<error>%s</error>', str_repeat(' ', $len));
@@ -801,6 +801,13 @@ protected function doRenderException(\Exception $e, OutputInterface $output)
801801
// exception related properties
802802
$trace = $e->getTrace();
803803

804+
array_unshift($trace, array(
805+
'function' => '',
806+
'file' => $e->getFile() ?? 'n/a',
807+
'line' => $e->getLine() ?? 'n/a',
808+
'args' => array(),
809+
));
810+
804811
for ($i = 0, $count = \count($trace); $i < $count; ++$i) {
805812
$class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
806813
$type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,20 @@ public function testRenderAnonymousException()
849849
$this->assertContains('Dummy type "@anonymous" is invalid.', $tester->getDisplay(true));
850850
}
851851

852+
public function testRenderExceptionStackTraceContainsRootException()
853+
{
854+
$application = new Application();
855+
$application->setAutoExit(false);
856+
$application->register('foo')->setCode(function () {
857+
throw new \Exception('Verbose exception');
858+
});
859+
860+
$tester = new ApplicationTester($application);
861+
$tester->run(array('command' => 'foo'), array('decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));
862+
863+
$this->assertContains(sprintf('() at %s:', __FILE__), $tester->getDisplay());
864+
}
865+
852866
public function testRun()
853867
{
854868
$application = new Application();

0 commit comments

Comments
 (0)
0