bug #13767 [HttpKernel] Throw double-bounce exceptions (nicolas-grekas)

This PR was merged into the 2.3 branch.

Discussion
----------

[HttpKernel] Throw double-bounce exceptions

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Commits
-------

0ebcf63 [HttpKernel] Throw double-bounce exceptions
This commit is contained in:
Fabien Potencier 2015-02-25 12:22:04 +01:00
commit 7d6c7a3cef
2 changed files with 11 additions and 9 deletions

View File

@ -67,13 +67,13 @@ class ExceptionListener implements EventSubscriberInterface
try {
$response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
} catch (\Exception $e) {
$this->logException($exception, sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()), false);
$this->logException($e, sprintf('Exception thrown when handling an exception (%s: %s at %s line %s)', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()), false);
// set handling to false otherwise it wont be able to handle further more
$handling = false;
// re-throw the exception from within HttpKernel as this is a catch-all
return;
// throwing $e, not $exception, is on purpose: fixing error handling code paths is the most important
throw $e;
}
$event->setResponse($response);
@ -91,7 +91,7 @@ class ExceptionListener implements EventSubscriberInterface
/**
* Logs an exception.
*
* @param \Exception $exception The original \Exception instance
* @param \Exception $exception The \Exception instance
* @param string $message The error message to log
* @param bool $original False when the handling of the exception thrown another exception
*/

View File

@ -54,8 +54,9 @@ class ExceptionListenerTest extends \PHPUnit_Framework_TestCase
try {
$l->onKernelException($event2);
} catch (\Exception $e) {
$this->assertSame('foo', $e->getMessage());
$this->fail('RuntimeException expected');
} catch (\RuntimeException $e) {
$this->assertSame('bar', $e->getMessage());
}
}
@ -73,8 +74,9 @@ class ExceptionListenerTest extends \PHPUnit_Framework_TestCase
try {
$l->onKernelException($event2);
} catch (\Exception $e) {
$this->assertSame('foo', $e->getMessage());
$this->fail('RuntimeException expected');
} catch (\RuntimeException $e) {
$this->assertSame('bar', $e->getMessage());
}
$this->assertEquals(3, $logger->countErrors());
@ -137,6 +139,6 @@ class TestKernelThatThrowsException implements HttpKernelInterface
{
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
{
throw new \Exception('bar');
throw new \RuntimeException('bar');
}
}