[Console] Display file and line on Exception
This commit is contained in:
parent
dd3276c2e8
commit
484d278f50
@ -736,13 +736,13 @@ class Application
|
||||
protected function doRenderException(\Exception $e, OutputInterface $output)
|
||||
{
|
||||
do {
|
||||
$title = sprintf(
|
||||
' [%s%s] ',
|
||||
get_class($e),
|
||||
$output->isVerbose() && 0 !== ($code = $e->getCode()) ? ' ('.$code.')' : ''
|
||||
);
|
||||
|
||||
$message = $e->getMessage();
|
||||
if ('' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
|
||||
$title = sprintf(' [%s%s] ', get_class($e), 0 !== ($code = $e->getCode()) ? ' ('.$code.')' : '');
|
||||
$len = Helper::strlen($title);
|
||||
} else {
|
||||
$len = 0;
|
||||
}
|
||||
|
||||
$width = $this->terminal->getWidth() ? $this->terminal->getWidth() - 1 : PHP_INT_MAX;
|
||||
// HHVM only accepts 32 bits integer in str_split, even when PHP_INT_MAX is a 64 bit integer: https://github.com/facebook/hhvm/issues/1327
|
||||
@ -750,7 +750,7 @@ class Application
|
||||
$width = 1 << 31;
|
||||
}
|
||||
$lines = array();
|
||||
foreach (preg_split('/\r?\n/', $e->getMessage()) as $line) {
|
||||
foreach ('' !== $message ? preg_split('/\r?\n/', $message) : array() as $line) {
|
||||
foreach ($this->splitStringByWidth($line, $width - 4) as $line) {
|
||||
// pre-format lines to get the right string length
|
||||
$lineLength = Helper::strlen($line) + 4;
|
||||
@ -761,8 +761,11 @@ class Application
|
||||
}
|
||||
|
||||
$messages = array();
|
||||
$messages[] = sprintf('<comment>%s</comment>', OutputFormatter::escape(sprintf('In %s line %s:', basename($e->getFile()) ?: 'n/a', $e->getLine() ?: 'n/a')));
|
||||
$messages[] = $emptyLine = sprintf('<error>%s</error>', str_repeat(' ', $len));
|
||||
if ('' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
|
||||
$messages[] = sprintf('<error>%s%s</error>', $title, str_repeat(' ', max(0, $len - Helper::strlen($title))));
|
||||
}
|
||||
foreach ($lines as $line) {
|
||||
$messages[] = sprintf('<error> %s %s</error>', OutputFormatter::escape($line[0]), str_repeat(' ', $len - $line[1]));
|
||||
}
|
||||
@ -776,12 +779,6 @@ class Application
|
||||
|
||||
// exception related properties
|
||||
$trace = $e->getTrace();
|
||||
array_unshift($trace, array(
|
||||
'function' => '',
|
||||
'file' => $e->getFile() !== null ? $e->getFile() : 'n/a',
|
||||
'line' => $e->getLine() !== null ? $e->getLine() : 'n/a',
|
||||
'args' => array(),
|
||||
));
|
||||
|
||||
for ($i = 0, $count = count($trace); $i < $count; ++$i) {
|
||||
$class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
In Application.php line 615:
|
||||
|
||||
[Symfony\Component\Console\Exception\CommandNotFoundException]
|
||||
Command "foo" is not defined.
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
In ArrayInput.php line 172:
|
||||
|
||||
[Symfony\Component\Console\Exception\InvalidOptionException]
|
||||
The "--foo" option does not exist.
|
||||
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
|
||||
In Foo3Command.php line 26:
|
||||
|
||||
[Exception]
|
||||
Third exception <fg=blue;bg=red>comment</>
|
||||
|
||||
|
||||
In Foo3Command.php line 23:
|
||||
|
||||
[Exception]
|
||||
Second exception <comment>comment</comment>
|
||||
|
||||
|
||||
In Foo3Command.php line 21:
|
||||
|
||||
[Exception]
|
||||
First exception <p>this is html</p>
|
||||
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
|
||||
[33mIn Foo3Command.php line 26:[39m
|
||||
[37;41m [39;49m
|
||||
[37;41m [Exception] [39;49m
|
||||
[37;41m Third exception <fg=blue;bg=red>comment</> [39;49m
|
||||
[37;41m [39;49m
|
||||
|
||||
[33mIn Foo3Command.php line 23:[39m
|
||||
[37;41m [39;49m
|
||||
[37;41m [Exception] [39;49m
|
||||
[37;41m Second exception <comment>comment</comment> [39;49m
|
||||
[37;41m [39;49m
|
||||
|
||||
[33mIn Foo3Command.php line 21:[39m
|
||||
[37;41m [39;49m
|
||||
[37;41m [Exception] [39;49m
|
||||
[37;41m First exception <p>this is html</p> [39;49m
|
||||
[37;41m [39;49m
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
In Application.php line 615:
|
||||
|
||||
[Symfony\Component\Console\Exception\CommandNotFoundException]
|
||||
Command "foo" is not define
|
||||
d.
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
In ApplicationTest.php line 716:
|
||||
|
||||
[Exception]
|
||||
エラーメッセージ
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
[33mIn ApplicationTest.php line 716:[39m
|
||||
[37;41m [39;49m
|
||||
[37;41m [Exception] [39;49m
|
||||
[37;41m エラーメッセージ [39;49m
|
||||
[37;41m [39;49m
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
In ApplicationTest.php line 730:
|
||||
|
||||
[Exception]
|
||||
コマンドの実行中にエラーが
|
||||
発生しました。
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
In ApplicationTest.php line 744:
|
||||
|
||||
[Exception]
|
||||
dont break here <
|
||||
info>!</info>
|
||||
|
||||
|
Reference in New Issue
Block a user