8000 bug #13767 [HttpKernel] Throw double-bounce exceptions (nicolas-grekas) · symfony/symfony@7d6c7a3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7d6c7a3

Browse files
committed
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
2 parents ab7b3a8 + 0ebcf63 commit 7d6c7a3

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ public function onKernelException(GetResponseForExceptionEvent $event)
6767
try {
6868
$response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
6969
} catch (\Exception $e) {
70-
$this->logException($exception, sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()), false);
70+
$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);
7171

7272
// set handling to false otherwise it wont be able to handle further more
7373
$handling = false;
7474

75-
// re-throw the exception from within HttpKernel as this is a catch-all
76-
return;
75+
// throwing $e, not $exception, is on purpose: fixing error handling code paths is the most important
76+
throw $e;
7777
}
7878

7979
$event->setResponse($response);
@@ -91,7 +91,7 @@ public static function getSubscribedEvents()
9191
/**
9292
* Logs an exception.
9393
*
94-
* @param \Exception $exception The original \Exception instance
94+
* @param \Exception $exception The \Exception instance
9595
* @param string $message The error message to log
9696
* @param bool $original False when the handling of the exception thrown another exception
9797
*/

src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ public function testHandleWithoutLogger($event, $event2)
5454

5555
try {
5656
$l->onKernelException($event2);
57-
} catch (\Exception $e) {
58-
$this->assertSame('foo', $e->getMessage());
57+
$this->fail('RuntimeException expected');
58+
} catch (\RuntimeException $e) {
59+
$this->assertSame('bar', $e->getMessage());
5960
}
6061
}
6162

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

7475
try {
7576
$l->onKernelException($event2);
76-
} catch (\Exception $e) {
77-
$this->assertSame('foo', $e->getMessage());
77+
$this->fail('RuntimeException expected');
78+
} catch (\RuntimeException $e) {
79+
$this->assertSame('bar', $e->getMessage());
7880
}
7981

8082
$this->assertEquals(3, $logger->countErrors());
@@ -137,6 +139,6 @@ class TestKernelThatThrowsException implements HttpKernelInterface
137139
{
138140
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
139141
{
140-
throw new \Exception('bar');
142+
throw new \RuntimeException('bar');
141143
}
142144
}

0 commit comments

Comments
 (0)
0