Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 22f4807

Browse filesBrowse files
[HttpKernel] Throw a LogicException when kernel.exception does not led to a Response
1 parent 2b036ec commit 22f4807
Copy full SHA for 22f4807

File tree

Expand file treeCollapse file tree

4 files changed

+17
-19
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+17
-19
lines changed

‎src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php
+4-9Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,15 @@ public static function getSubscribedEvents()
8383
*
8484
* @param \Exception $exception The \Exception instance
8585
* @param string $message The error message to log
86-
* @param bool $original False when the handling of the exception thrown another exception
8786
*/
88-
protected function logException(\Exception $exception, $message, $original = true)
87+
protected function logException(\Exception $exception, $message)
8988
{
90-
$isCritical = !$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500;
91-
$context = array('exception' => $exception);
9289
if (null !== $this->logger) {
93-
if ($isCritical) {
94-
$this->logger->critical($message, $context);
90+
if (!$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500) {
91+
$this->logger->critical($message, array('exception' => $exception));
9592
} else {
96-
$this->logger->error($message, $context);
93+
$this->logger->error($message, array('exception' => $exception));
9794
}
98-
} elseif (!$original || $isCritical) {
99-
error_log($message);
10095
}
10196
}
10297

‎src/Symfony/Component/HttpKernel/HttpKernel.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/HttpKernel.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private function handleException(\Exception $e, $request, $type)
229229
if (!$event->hasResponse()) {
230230
$this->finishRequest($request, $type);
231231

232-
throw $e;
232+
throw new \LogicException('No listeners of the "kernel.exception" event set a Response', 0, $e);
233233
}
234234

235235
$response = $event->getResponse();

‎src/Symfony/Component/HttpKernel/Tests/DependencyInjection/ContainerAwareHttpKernelTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/DependencyInjection/ContainerAwareHttpKernelTest.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ public function testHandleRestoresThePreviousRequestOnException($type)
102102
$this->fail('->handle() suppresses the controller exception');
103103
} catch (\PHPUnit_Framework_Exception $exception) {
104104
throw $exception;
105-
} catch (\Exception $actual) {
106-
$this->assertSame($expected, $actual, '->handle() throws the controller exception');
105+
} catch (\LogicException $actual) {
106+
$this->assertSame($expected, $actual->getPrevious(), '->handle() throws the controller exception, wrapped when no listener');
107107
}
108108
}
109109

‎src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php
+10-7Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@
2323

2424
class HttpKernelTest extends \PHPUnit_Framework_TestCase
2525
{
26-
/**
27-
* @expectedException \RuntimeException
28-
*/
2926
public function testHandleWhenControllerThrowsAnExceptionAndRawIsTrue()
3027
{
31-
$kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () { throw new \RuntimeException(); }));
32-
33-
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
28+
$exception = new \RuntimeException();
29+
$kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () use ($exception) { throw $exception; }));
30+
31+
try {
32+
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
33+
$this->fail('LogicException expected');
34+
} catch (\LogicException $e) {
35+
$this->assertSame($exception, $e->getPrevious());
36+
}
3437
}
3538

3639
/**
@@ -132,7 +135,7 @@ public function testHandleWhenNoControllerIsFound()
132135
$dispatcher = new EventDispatcher();
133136
$kernel = new HttpKernel($dispatcher, $this->getResolver(false));
134137

135-
$kernel->handle(new Request());
138+
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, false);
136139
}
137140

138141
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.