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 6e48ec9

Browse filesBrowse files
[HttpKernel] Fix logging of post-terminate errors/exceptions
1 parent 40ced3a commit 6e48ec9
Copy full SHA for 6e48ec9

File tree

2 files changed

+22
-15
lines changed
Filter options

2 files changed

+22
-15
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php
+19-10Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Debug\ExceptionHandler;
1717
use Symfony\Component\EventDispatcher\Event;
1818
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
19+
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
1920
use Symfony\Component\HttpKernel\Event\KernelEvent;
2021
use Symfony\Component\HttpKernel\KernelEvents;
2122
use Symfony\Component\Console\ConsoleEvents;
@@ -36,6 +37,7 @@ class DebugHandlersListener implements EventSubscriberInterface
3637
private $scream;
3738
private $fileLinkFormat;
3839
private $firstCall = true;
40+
private $hasTerminatedWithException;
3941

4042
/**
4143
* @param callable|null $exceptionHandler A handler that will be called on Exception
@@ -60,14 +62,16 @@ public function __construct($exceptionHandler, LoggerInterface $logger = null, $
6062
*/
6163
public function configure(Event $event = null)
6264
{
63-
if (!$this->firstCall) {
65+
if (!$event instanceof GetResponseEvent ? !$this->firstCall : !$event->getRequest()->isMasterRequest()) {
6466
return;
6567
}
66-
$this->firstCall = false;
68+
$this->firstCall = $this->hasTerminatedWithException = false;
69+
70+
$handler = set_exception_handler('var_dump');
71+
$handler = is_array($handler) ? $handler[0] : null;
72+
restore_exception_handler();
73+
6774
if ($this->logger || null !== $this->throwAt) {
68-
$handler = set_error_handler('var_dump');
69-
$handler = is_array($handler) ? $handler[0] : null;
70-
restore_error_handler();
7175
if ($handler instanceof ErrorHandler) {
7276
if ($this->logger) {
7377
$handler->setDefaultLogger($this->logger, $this->levels);
@@ -91,8 +95,16 @@ public function configure(Event $event = null)
9195
}
9296
if (!$this->exceptionHandler) {
9397
if ($event instanceof KernelEvent) {
94-
if (method_exists($event->getKernel(), 'terminateWithException')) {
95-
$this->exceptionHandler = array($event->getKernel(), 'terminateWithException');
98+
if (method_exists($kernel = $event->getKernel(), 'terminateWithException')) {
99+
$request = $event->getRequest();
100+
$hasRun = &$this->hasTerminatedWithException;
101+
$this->exceptionHandler = function (\Exception $e) use ($kernel, $request, &$hasRun) {
102+
if ($hasRun) {
103+
throw $e;
104+
}
105+
$hasRun = true;
106+
$kernel->terminateWithException($e, $request);
107+
};
96108
}
97109
} elseif ($event instanceof ConsoleEvent && $app = $event->getCommand()->getApplication()) {
98110
$output = $event->getOutput();
@@ -105,9 +117,6 @@ public function configure(Event $event = null)
105117
}
106118
}
107119
if ($this->exceptionHandler) {
108-
$handler = set_exception_handler('var_dump');
109-
$handler = is_array($handler) ? $handler[0] : null;
110-
restore_exception_handler();
111120
if ($handler instanceof ErrorHandler) {
112121
$h = $handler->setExceptionHandler('var_dump') ?: $this->exceptionHandler;
113122
$handler->setExceptionHandler($h);

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/HttpKernel.php
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,12 @@ public function terminate(Request $request, Response $response)
7878
}
7979

8080
/**
81-
* @throws \LogicException If the request stack is empty
82-
*
8381
* @internal
8482
*/
85-
public function terminateWithException(\Exception $exception)
83+
public function terminateWithException(\Exception $exception, Request $request = null)
8684
{
87-
if (!$request = $this->requestStack->getMasterRequest()) {
88-
throw new \LogicException('Request stack is empty', 0, $exception);
85+
if (!$request = $request ?: $this->requestStack->getMasterRequest()) {
86+
throw $exception;
8987
}
9088

9189
$response = $this->handleException($exception, $request, self::MASTER_REQUEST);

0 commit comments

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