diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php
index c1731843e6eb2..41c2a238e08a1 100644
--- a/src/Symfony/Component/Console/Application.php
+++ b/src/Symfony/Component/Console/Application.php
@@ -736,13 +736,13 @@ public function renderException(\Exception $e, OutputInterface $output)
protected function doRenderException(\Exception $e, OutputInterface $output)
{
do {
- $title = sprintf(
- ' [%s%s] ',
- get_class($e),
- $output->isVerbose() && 0 !== ($code = $e->getCode()) ? ' ('.$code.')' : ''
- );
-
- $len = Helper::strlen($title);
+ $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 @@ protected function doRenderException(\Exception $e, OutputInterface $output)
$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 @@ protected function doRenderException(\Exception $e, OutputInterface $output)
}
$messages = array();
+ $messages[] = sprintf('%s', OutputFormatter::escape(sprintf('In %s line %s:', basename($e->getFile()) ?: 'n/a', $e->getLine() ?: 'n/a')));
$messages[] = $emptyLine = sprintf('%s', str_repeat(' ', $len));
- $messages[] = sprintf('%s%s', $title, str_repeat(' ', max(0, $len - Helper::strlen($title))));
+ if ('' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
+ $messages[] = sprintf('%s%s', $title, str_repeat(' ', max(0, $len - Helper::strlen($title))));
+ }
foreach ($lines as $line) {
$messages[] = sprintf(' %s %s', OutputFormatter::escape($line[0]), str_repeat(' ', $len - $line[1]));
}
@@ -776,12 +779,6 @@ protected function doRenderException(\Exception $e, OutputInterface $output)
// 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'] : '';
diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception1.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception1.txt
index 919cec4214a97..700ffada3d2fa 100644
--- a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception1.txt
+++ b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception1.txt
@@ -1,6 +1,6 @@
-
- [Symfony\Component\Console\Exception\CommandNotFoundException]
- Command "foo" is not defined.
-
+In Application.php line 615:
+
+ Command "foo" is not defined.
+
diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt
index 64561715e04fb..9d0cacb81aedc 100644
--- a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt
+++ b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt
@@ -1,8 +1,8 @@
-
- [Symfony\Component\Console\Exception\InvalidOptionException]
- The "--foo" option does not exist.
-
+In ArrayInput.php line 172:
+
+ The "--foo" option does not exist.
+
list [--raw] [--format FORMAT] [--] []
diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception3.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception3.txt
index f41925f52a6ea..5366b84f82304 100644
--- a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception3.txt
+++ b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception3.txt
@@ -1,16 +1,16 @@
+In Foo3Command.php line 26:
- [Exception]
Third exception comment>
+In Foo3Command.php line 23:
- [Exception]
Second exception comment
+In Foo3Command.php line 21:
- [Exception]
First exception this is html
diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception3decorated.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception3decorated.txt
index 5adccdd70245f..59937092e78da 100644
--- a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception3decorated.txt
+++ b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception3decorated.txt
@@ -1,16 +1,16 @@
+[33mIn Foo3Command.php line 26:[39m
[37;41m [39;49m
-[37;41m [Exception] [39;49m
[37;41m Third exception 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 [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 this is html
[39;49m
[37;41m [39;49m
diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception4.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception4.txt
index cb080e9cb53b8..040564447f57b 100644
--- a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception4.txt
+++ b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception4.txt
@@ -1,7 +1,7 @@
-
- [Symfony\Component\Console\Exception\CommandNotFoundException]
- Command "foo" is not define
- d.
-
+In Application.php line 615:
+
+ Command "foo" is not define
+ d.
+
diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception_doublewidth1.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception_doublewidth1.txt
index 1ba5f8fdd914d..01986c917b545 100644
--- a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception_doublewidth1.txt
+++ b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception_doublewidth1.txt
@@ -1,6 +1,6 @@
+In ApplicationTest.php line 716:
- [Exception]
エラーメッセージ
diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception_doublewidth1decorated.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception_doublewidth1decorated.txt
index 20644251c2f9b..ba057d8cc77ff 100644
--- a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception_doublewidth1decorated.txt
+++ b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception_doublewidth1decorated.txt
@@ -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
diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception_doublewidth2.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception_doublewidth2.txt
index e41fcfcf675af..66b52c879a66a 100644
--- a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception_doublewidth2.txt
+++ b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception_doublewidth2.txt
@@ -1,6 +1,6 @@
+In ApplicationTest.php line 730:
- [Exception]
コマンドの実行中にエラーが
発生しました。
diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception_escapeslines.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception_escapeslines.txt
index cf79b37a92d6e..326ee42f6d741 100644
--- a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception_escapeslines.txt
+++ b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception_escapeslines.txt
@@ -1,6 +1,6 @@
+In ApplicationTest.php line 744:
- [Exception]
dont break here <
info>!