[Console] Show code when an exception is thrown
This commit is contained in:
parent
ed2cdfa827
commit
f8cd9e8263
@ -588,7 +588,11 @@ class Application
|
|||||||
$output->writeln('', OutputInterface::VERBOSITY_QUIET);
|
$output->writeln('', OutputInterface::VERBOSITY_QUIET);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
$title = sprintf(' [%s] ', get_class($e));
|
$title = sprintf(
|
||||||
|
' [%s%s] ',
|
||||||
|
get_class($e),
|
||||||
|
$output->isVerbose() && 0 !== ($code = $e->getCode()) ? ' ('.$code.')' : ''
|
||||||
|
);
|
||||||
|
|
||||||
$len = $this->stringWidth($title);
|
$len = $this->stringWidth($title);
|
||||||
|
|
||||||
|
@ -520,6 +520,11 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
|||||||
$tester->run(array('command' => 'foo3:bar'), array('decorated' => false));
|
$tester->run(array('command' => 'foo3:bar'), array('decorated' => false));
|
||||||
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3.txt', $tester->getDisplay(true), '->renderException() renders a pretty exceptions with previous exceptions');
|
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3.txt', $tester->getDisplay(true), '->renderException() renders a pretty exceptions with previous exceptions');
|
||||||
|
|
||||||
|
$tester->run(array('command' => 'foo3:bar'), array('decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));
|
||||||
|
$this->assertRegExp('/\[Exception\]\s*First exception/', $tester->getDisplay(), '->renderException() renders a pretty exception without code exception when code exception is default and verbosity is verbose');
|
||||||
|
$this->assertRegExp('/\[Exception\]\s*Second exception/', $tester->getDisplay(), '->renderException() renders a pretty exception without code exception when code exception is 0 and verbosity is verbose');
|
||||||
|
$this->assertRegExp('/\[Exception \(404\)\]\s*Third exception/', $tester->getDisplay(), '->renderException() renders a pretty exception with code exception when code exception is 404 and verbosity is verbose');
|
||||||
|
|
||||||
$tester->run(array('command' => 'foo3:bar'), array('decorated' => true));
|
$tester->run(array('command' => 'foo3:bar'), array('decorated' => true));
|
||||||
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3decorated.txt', $tester->getDisplay(true), '->renderException() renders a pretty exceptions with previous exceptions');
|
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3decorated.txt', $tester->getDisplay(true), '->renderException() renders a pretty exceptions with previous exceptions');
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class Foo3Command extends Command
|
|||||||
throw new \Exception('Second exception <comment>comment</comment>', 0, $e);
|
throw new \Exception('Second exception <comment>comment</comment>', 0, $e);
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
throw new \Exception('Third exception <fg=blue;bg=red>comment</>', 0, $e);
|
throw new \Exception('Third exception <fg=blue;bg=red>comment</>', 404, $e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user