Skip to content

Commit

Permalink
bug symfony#13767 [HttpKernel] Throw double-bounce exceptions (nicola…
Browse files Browse the repository at this point in the history
…s-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
  • Loading branch information
fabpot committed Feb 25, 2015
2 parents ab7b3a8 + 0ebcf63 commit 7d6c7a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ public function onKernelException(GetResponseForExceptionEvent $event)
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);
Expand All @@ -91,7 +91,7 @@ public static function getSubscribedEvents()
/**
* 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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ public function testHandleWithoutLogger($event, $event2)

try {
$l->onKernelException($event2);
} catch (\Exception $e) {
$this->assertSame('foo', $e->getMessage());
$this->fail('RuntimeException expected');
} catch (\RuntimeException $e) {
$this->assertSame('bar', $e->getMessage());
}
}

Expand All @@ -73,8 +74,9 @@ public function testHandleWithLogger($event, $event2)

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());
Expand Down Expand Up @@ -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');
}
}

0 comments on commit 7d6c7a3

Please sign in to comment.