8000 [Debug] fix and enhance exception messages · symfony/symfony@afb4d1b · GitHub
[go: up one dir, main page]

Skip to content

Commit afb4d1b

Browse files
[Debug] fix and enhance exception messages
1 parent 1d7684a commit afb4d1b

9 files changed

+28
-26
lines changed

src/Symfony/Component/Debug/ExceptionHandler.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,11 @@ public function getContent(FlattenException $exception)
210210
$class = $this->formatClass($e['class']);
211211
$message = nl2br(self::utf8Htmlize($e['message']));
212212
$content .= sprintf(<<<EOF
213-
<div class="block_exception clear_fix">
214-
<h2><span>%d/%d</span> %s%s:<br />%s</h2>
215-
</div>
213+
<h2 class="block_exception clear_fix">
214+
<div class="exception_counter"><span>%d/%d</span></div>
215+
<div class="exception_title">%s%s:</div>
216+
<div class="exception_message">%s</div>
217+
</h2>
216218
<div class="block">
217219
<ol class="traces list_exception">
218220
@@ -269,12 +271,14 @@ public function getStylesheet(FlattenException $exception)
269271
.sf-reset abbr { border-bottom: 1px dotted #000; cursor: help; }
270272
.sf-reset p { font-size:14px; line-height:20px; color:#868686; padding-bottom:20px }
271273
.sf-reset strong { font-weight:bold; }
272-
.sf-reset a { color:#6c6159; }
274+
.sf-reset a { color:#6c6159; cursor: default; }
273275
.sf-reset a img { border:none; }
274276
.sf-reset a:hover { text-decoration:underline; }
275277
.sf-reset em { font-style:italic; }
276278
.sf-reset h1, .sf-reset h2 { font: 20px Georgia, "Times New Roman", Times, serif }
277-
.sf-reset h2 span { background-color: #fff; color: #333; padding: 6px; float: left; margin-right: 10px; }
279+
.sf-reset .exception_counter { background-color: #fff; color: #333; padding: 6px; float: left; margin-right: 10px; float: left; }
280+
.sf-reset .exception_title { margin-left: 3em; margin-bottom: 0.7em; }
281+
.sf-reset .exception_message { margin-left: 3em; }
278282
.sf-reset .traces li { font-size:12px; padding: 2px 4px; list-style-type:decimal; margin-left:20px; }
279283
.sf-reset .block { background-color:#FFFFFF; padding:10px 28px; margin-bottom:20px;
280284
-webkit-border-bottom-right-radius: 16px;
@@ -352,10 +356,10 @@ private function formatPath($path, $line)
352356
if ($linkFormat = ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format')) {
353357
$link = str_replace(array('%f', '%l'), array($path, $line), $linkFormat);
354358

355-
return sprintf(' <a href="%s" title="Go to source">in %s line %d</a>', $link, $file, $line);
359+
return sprintf(' in <a href="%s" title="Go to source">%s line %d</a>', $link, $file, $line);
356360
}
357361

358-
return sprintf(' <a title="in %s line %3$d" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">in %s line %d</a>', $path, $file, $line);
362+
return sprintf(' in <a title="%s line %3$d" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">%s line %d</a>', $path, $file, $line);
359363
}
360364

361365
/**

src/Symfony/Component/Debug/FatalErrorHandler/ClassNotFoundFatalErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function handleError(array $error, FatalErrorException $exception)
6767
$tail = ' for "'.$tail;
6868
}
6969
}
70-
$message .= ' Did you forget a "use" statement'.$tail;
70+
$message .= "\nDid you forget a \"use\" statement".$tail;
7171

7272
return new ClassNotFoundException($message, $exception);
7373
}

src/Symfony/Component/Debug/FatalErrorHandler/UndefinedFunctionFatalErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function handleError(array $error, FatalErrorException $exception)
7676
} else {
7777
$candidates = '"'.$last;
7878
}
79-
$message .= ' Did you mean to call '.$candidates;
79+
$message .= "\nDid you mean to call ".$candidates;
8080
}
8181

8282
return new UndefinedFunctionException($message, $exception);

src/Symfony/Component/Debug/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function handleError(array $error, FatalErrorException $exception)
5252
} else {
5353
$candidates = '"'.$last;
5454
}
55-
$message .= ' Did you mean to call '.$candidates;
55+
$message .= "\nDid you mean to call ".$candidates;
5656
}
5757

5858
return new UndefinedMethodException($message, $exception);

src/Symfony/Component/Debug/Tests/ExceptionHandlerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ public function testDebug()
2525
$response = $handler->createResponse(new \Run F438 timeException('Foo'));
2626

2727
$this->assertContains('<h1>Whoops, looks like something went wrong.</h1>', $response->getContent());
28-
$this->assertNotContains('<div class="block_exception clear_fix">', $response->getContent());
28+
$this->assertNotContains('<h2 class="block_exception clear_fix">', $response->getContent());
2929

3030
$handler = new ExceptionHandler(true);
3131
$response = $handler->createResponse(new \RuntimeException('Foo'));
3232

3333
$this->assertContains('<h1>Whoops, looks like something went wrong.</h1>', $response->getContent());
34-
$this->assertContains('<div class="block_exception clear_fix">', $response->getContent());
34+
$this->assertContains('<h2 class="block_exception clear_fix">', $response->getContent());
3535
}
3636

3737
public function testStatusCode()

src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function provideClassNotFoundData()
4141
'file' => 'foo.php',
4242
'message' => 'Class \'WhizBangFactory\' not found',
4343
),
44-
'Attempted to load class "WhizBangFactory" from the global namespace. Did you forget a "use" statement?',
44+
"Attempted to load class \"WhizBangFactory\" from the global namespace.\nDid you forget a \"use\" statement?",
4545
),
4646
array(
4747
array(
@@ -50,7 +50,7 @@ public function provideClassNotFoundData()
5050
'file' => 'foo.php',
5151
'message' => 'Class \'Foo\\Bar\\WhizBangFactory\' not found',
5252
),
53-
'Attempted to load class "WhizBangFactory" from namespace "Foo\\Bar". Did you forget a "use" statement for another namespace?',
53+
"Attempted to load class \"WhizBangFactory\" from namespace \"Foo\\Bar\".\nDid you forget a \"use\" statement for another namespace?",
5454
),
5555
array(
5656
array(
@@ -59,7 +59,7 @@ public function provideClassNotFoundData()
5959
'file' => 'foo.php',
6060
'message' => 'Class \'UndefinedFunctionException\' not found',
6161
),
62-
'Attempted to load class "UndefinedFunctionException" from the global namespace. Did you forget a "use" statement for "Symfony\Component\Debug\Exception\UndefinedFunctionException"?',
62+
"Attempted to load class \"UndefinedFunctionException\" from the global namespace.\nDid you forget a \"use\" statement for \"Symfony\Component\Debug\Exception\UndefinedFunctionException\"?",
6363
),
6464
array(
6565
array(
@@ -68,7 +68,7 @@ public function provideClassNotFoundData()
6868
'file' => 'foo.php',
6969
'message' => 'Class \'PEARClass\' not found',
7070
),
71-
'Attempted to load class "PEARClass" from the global namespace. Did you forget a "use" statement for "Symfony_Component_Debug_Tests_Fixtures_PEARClass"?',
71+
"Attempted to load class \"PEARClass\" from the global namespace.\nDid you forget a \"use\" statement for \"Symfony_Component_Debug_Tests_Fixtures_PEARClass\"?",
7272
),
7373
array(
7474
array(
@@ -77,7 +77,7 @@ public function provideClassNotFoundData()
7777
'file' => 'foo.php',
7878
'message' => 'Class \'Foo\\Bar\\UndefinedFunctionException\' not found',
7979
),
80-
'Attempted to load class "UndefinedFunctionException" from namespace "Foo\Bar". Did you forget a "use" statement for "Symfony\Component\Debug\Exception\UndefinedFunctionException"?',
80+
"Attempted to load class \"UndefinedFunctionException\" from namespace \"Foo\Bar\".\nDid you forget a \"use\" statement for \"Symfony\Component\Debug\Exception\UndefinedFunctionException\"?",
8181
),
8282
);
8383
}

src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedFunctionFatalErrorHandlerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function provideUndefinedFunctionData()
4242
'file' => 'foo.php',
4343
'message' => 'Call to undefined function test_namespaced_function()',
4444
),
45-
'Attempted to call function "test_namespaced_function" from the global namespace. Did you mean to call "\\symfony\\component\\debug\\tests\\fatalerrorhandler\\test_namespaced_function"?',
45+
"Attempted to call function \"test_namespaced_function\" from the global namespace.\nDid you mean to call \"\\symfony\\component\\debug\\tests\\fatalerrorhandler\\test_namespaced_function\"?",
4646
),
4747
array(
4848
array(
@@ -51,7 +51,7 @@ public function provideUndefinedFunctionData()
5151
'file' => 'foo.php',
5252
'message' => 'Call to undefined function Foo\\Bar\\Baz\\test_namespaced_function()',
5353
),
54-
'Attempted to call function "test_namespaced_function" from namespace "Foo\\Bar\\Baz". Did you mean to call "\\symfony\\component\\debug\\tests\\fatalerrorhandler\\test_namespaced_function"?',
54+
"Attempted to call function \"test_namespaced_function\" from namespace \"Foo\\Bar\\Baz\".\nDid you mean to call \"\\symfony\\component\\debug\\tests\\fatalerrorhandler\\test_namespaced_function\"?",
5555
),
5656
array(
5757
array(

src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function provideUndefinedMethodData()
5050
'file' => 'foo.php',
5151
'message' => 'Call to undefined method SplObjectStorage::walid()',
5252
),
53-
'Attempted to call method "walid" on class "SplObjectStorage". Did you mean to call "valid"?',
53+
"Attempted to call method \"walid\" on class \"SplObjectStorage\".\nDid you mean to call \"valid\"?",
5454
),
5555
array(
5656
array(
@@ -59,7 +59,7 @@ public function provideUndefinedMethodData()
5959
'file' => 'foo.php',
6060
'message' => 'Call to undefined method SplObjectStorage::offsetFet()',
6161
),
62-
'Attempted to call method "offsetFet" on class "SplObjectStorage". Did you mean to call e.g. "offsetGet", "offsetSet" or "offsetUnset"?',
62+
"Attempted to call method \"offsetFet\" on class \"SplObjectStorage\".\nDid you mean to call e.g. \"offsetGet\", \"offsetSet\" or \"offsetUnset\"?",
6363
),
6464
);
6565
}

src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Psr\Log\LoggerInterface;
1515
use Symfony\Component\Debug\ErrorHandler;
16-
use Symfony\Component\Debug\AbstractExceptionHandler;
16+
use Symfony\Component\Debug\ExceptionHandler;
1717
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1818
use Symfony\Component\HttpKernel\KernelEvents;
1919

@@ -37,9 +37,7 @@ class DebugHandlersListener implements EventSubscriberInterface
3737
*/
3838
public function __construct($exceptionHandler, LoggerInterface $logger = null, $levels = null, $debug = true)
3939
{
40-
if (is_callable($exceptionHandler)) {
41-
$this->exceptionHandler = $exceptionHandler;
42-
}
40+
$this->exceptionHandler = $exceptionHandler;
4341
$this->logger = $logger;
4442
$this->levels = $levels;
4543
$this->debug = $debug;
@@ -76,7 +74,7 @@ public function configure()
7674
$handler->setExceptionHandler($h);
7775
$handler = is_array($h) ? $h[0] : null;
7876
}
79-
if ($handler instanceof AbstractExceptionHandler) {
77+
if ($handler instanceof ExceptionHandler) {
8078
$handler->setHandler($this->exceptionHandler);
8179
}
8280
$this->exceptionHandler = null;

0 commit comments

Comments
 (0)
0