8000 [HttpKernel] Fix logging of post-terminate errors/exceptions by nicolas-grekas · Pull Request #25410 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpKernel] Fix logging of post-terminate errors/exceptions #25410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading 8000
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class DebugHandlersListener implements EventSubscriberInterface
private $scream;
private $fileLinkFormat;
private $firstCall = true;
private $hasTerminatedWithException;

/**
* @param callable|null $exceptionHandler A handler that will be called on Exception
Expand All @@ -60,14 +61,16 @@ public function __construct($exceptionHandler, LoggerInterface $logger = null, $
*/
public function configure(Event $event = null)
{
if (!$this->firstCall) {
if (!$event instanceof KernelEvent ? !$this->firstCall : !$event->isMasterRequest()) {
return;
}
$this->firstCall = false;
$this->firstCall = $this->hasTerminatedWithException = false;

$handler = set_exception_handler('var_dump');
$handler = is_array($handler) ? $handler[0] : null;
restore_exception_handler();

if ($this->logger || null !== $this->throwAt) {
$handler = set_error_handler('var_dump');
$handler = is_array($handler) ? $handler[0] : null;
restore_error_handler();
if ($handler instanceof ErrorHandler) {
if ($this->logger) {
$handler->setDefaultLogge 8000 r($this->logger, $this->levels);
Expand All @@ -91,8 +94,16 @@ public function configure(Event $event = null)
}
if (!$this->exceptionHandler) {
if ($event instanceof KernelEvent) {
if (method_exists($event->getKernel(), 'terminateWithException')) {
$this->exceptionHandler = array($event->getKernel(), 'terminateWithException');
if (method_exists($kernel = $event->getKernel(), 'terminateWithException')) {
$request = $event->getRequest();
$hasRun = &$this->hasTerminatedWithException;
$this->exceptionHandler = function (\Exception $e) use ($kernel, $request, &$hasRun) {
if ($hasRun) {
throw $e;
}
$hasRun = true;
$kernel->terminateWithException($e, $request);
};
}
} elseif ($event instanceof ConsoleEvent && $app = $event->getCommand()->getApplication()) {
$output = $event->getOutput();
Expand All @@ -105,9 +116,6 @@ public function configure(Event $event = null)
}
}
if ($this->exceptionHandler) {
$handler = set_exception_handler('var_dump');
$handler = is_array($handler) ? $handler[0] : null;
restore_exception_handler();
if ($handler instanceof ErrorHandler) {
$h = $handler->setExceptionHandler('var_dump') ?: $this->exceptionHandler;
$handler->setExceptionHandler($h);
Expand Down
8 changes: 3 additions & 5 deletions src/Symfony/Component/HttpKernel/HttpKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,12 @@ public function terminate(Request $request, Response $response)
}

/**
* @throws \LogicException If the request stack is empty
*
* @internal
*/
public function terminateWithException(\Exception $exception)
public function terminateWithException(\Exception $exception, Request $request = null)
{
if (!$request = $this->requestStack->getMasterRequest()) {
throw new \LogicException('Request stack is empty', 0, $exception);
if (!$request = $request ?: $this->requestStack->getMasterRequest()) {
throw $exception;
}

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