Skip to content

Commit

Permalink
[Console] Move back root exception to stack trace in verbose mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Chalas committed Nov 26, 2018
1 parent 42c4bda commit 8f80fc3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,13 @@ protected function doRenderException(\Exception $e, OutputInterface $output)
// exception related properties
$trace = $e->getTrace();

array_unshift($trace, array(
'function' => '',
'file' => $e->getFile() ?: 'n/a',
'line' => $e->getLine() ?: 'n/a',
'args' => array(),
));

for ($i = 0, $count = \count($trace); $i < $count; ++$i) {
$class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
$type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';
Expand Down
14 changes: 14 additions & 0 deletions Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,20 @@ public function testRenderExceptionLineBreaks()
$this->assertStringMatchesFormatFile(self::$fixturesPath.'/application_renderexception_linebreaks.txt', $tester->getDisplay(true), '->renderException() keep multiple line breaks');
}

public function testRenderExceptionStackTraceContainsRootException()
{
$application = new Application();
$application->setAutoExit(false);
$application->register('foo')->setCode(function () {
throw new \Exception('Verbose exception');
});

$tester = new ApplicationTester($application);
$tester->run(array('command' => 'foo'), array('decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));

$this->assertContains(sprintf('() at %s:', __FILE__), $tester->getDisplay());
}

public function testRun()
{
$application = new Application();
Expand Down

0 comments on commit 8f80fc3

Please sign in to comment.