Skip to content

Commit c74f4d1

Browse files
committed
Merge branch '3.4' into 4.1
* 3.4: [Console] Move back root exception to stack trace in verbose mode
2 parents 261faeb + 8f80fc3 commit c74f4d1

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Application.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,13 @@ protected function doRenderException(\Exception $e, OutputInterface $output)
793793
// exception related properties
794794
$trace = $e->getTrace();
795795

796+
array_unshift($trace, array(
797+
'function' => '',
798+
'file' => $e->getFile() ?: 'n/a',
799+
'line' => $e->getLine() ?: 'n/a',
800+
'args' => array(),
801+
));
802+
796803
for ($i = 0, $count = \count($trace); $i < $count; ++$i) {
797804
$class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
798805
$type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';

Tests/ApplicationTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,20 @@ public function testRenderExceptionLineBreaks()
824824
$this->assertStringMatchesFormatFile(self::$fixturesPath.'/application_renderexception_linebreaks.txt', $tester->getDisplay(true), '->renderException() keep multiple line breaks');
825825
}
826826

827+
public function testRenderExceptionStackTraceContainsRootException()
828+
{
829+
$application = new Application();
830+
$application->setAutoExit(false);
831+
$application->register('foo')->setCode(function () {
832+
throw new \Exception('Verbose exception');
833+
});
834+
835+
$tester = new ApplicationTester($application);
836+
$tester->run(array('command' => 'foo'), array('decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));
837+
838+
$this->assertContains(sprintf('() at %s:', __FILE__), $tester->getDisplay());
839+
}
840+
827841
public function testRun()
828842
{
829843
$application = new Application();

0 commit comments

Comments
 (0)