Skip to content

Commit d6bbde5

Browse files
committed
bug #29318 [Console] Move back root exception to stack trace in verbose mode (chalasr)
This PR was merged into the 3.4 branch. Discussion ---------- [Console] Move back root exception to stack trace in verbose mode | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #29232 | License | MIT | Doc PR | n/a Commits ------- 63cd219 [Console] Move back root exception to stack trace in verbose mode
2 parents 1f59fa4 + 63cd219 commit d6bbde5

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/Symfony/Component/Console/Application.php

+7
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,13 @@ protected function doRenderException(\Exception $e, OutputInterface $output)
783783
// exception related properties
784784
$trace = $e->getTrace();
785785

786+
array_unshift($trace, array(
787+
'function' => '',
788+
'file' => $e->getFile() ?: 'n/a',
789+
'line' => $e->getLine() ?: 'n/a',
790+
'args' => array(),
791+
));
792+
786793
for ($i = 0, $count = \count($trace); $i < $count; ++$i) {
787794
$class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
788795
$type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';

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

+14
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,20 @@ public function testRenderExceptionLineBreaks()
776776
$this->assertStringMatchesFormatFile(self::$fixturesPath.'/application_renderexception_linebreaks.txt', $tester->getDisplay(true), '->renderException() keep multiple line breaks');
777777
}
778778

779+
public function testRenderExceptionStackTraceContainsRootException()
780+
{
781+
$application = new Application();
782+
$application->setAutoExit(false);
783+
$application->register('foo')->setCode(function () {
784+
throw new \Exception('Verbose exception');
785+
});
786+
787+
$tester = new ApplicationTester($application);
788+
$tester->run(array('command' => 'foo'), array('decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));
789+
790+
$this->assertContains(sprintf('() at %s:', __FILE__), $tester->getDisplay());
791+
}
792+
779793
public function testRun()
780794
{
781795
$application = new Application();

0 commit comments

Comments
 (0)