Skip to content

Commit

Permalink
bug #39944 [HttpKernel] Configure the ErrorHandler even when it is ov…
Browse files Browse the repository at this point in the history
…erriden (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpKernel] Configure the ErrorHandler even when it is overriden

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Fixes the part of getsentry/sentry-symfony#421 that is about `DebugHandlersListener`.

Commits
-------

31817b4 [HttpKernel] Configure the ErrorHandler even when it is overriden
  • Loading branch information
nicolas-grekas committed Jan 23, 2021
2 parents bf1752a + 31817b4 commit 799bc2a
Showing 1 changed file with 9 additions and 0 deletions.
Expand Up @@ -33,6 +33,7 @@
*/
class DebugHandlersListener implements EventSubscriberInterface
{
private $earlyHandler;
private $exceptionHandler;
private $logger;
private $levels;
Expand All @@ -53,6 +54,10 @@ class DebugHandlersListener implements EventSubscriberInterface
*/
public function __construct(callable $exceptionHandler = null, LoggerInterface $logger = null, $levels = \E_ALL, ?int $throwAt = \E_ALL, bool $scream = true, $fileLinkFormat = null, bool $scope = true)
{
$handler = set_exception_handler('var_dump');
$this->earlyHandler = \is_array($handler) ? $handler[0] : null;
restore_exception_handler();

$this->exceptionHandler = $exceptionHandler;
$this->logger = $logger;
$this->levels = null === $levels ? \E_ALL : $levels;
Expand All @@ -79,6 +84,10 @@ public function configure(Event $event = null)
$handler = \is_array($handler) ? $handler[0] : null;
restore_exception_handler();

if (!$handler instanceof ErrorHandler && !$handler instanceof LegacyErrorHandler) {
$handler = $this->earlyHandler;
}

if ($this->logger || null !== $this->throwAt) {
if ($handler instanceof ErrorHandler || $handler instanceof LegacyErrorHandler) {
if ($this->logger) {
Expand Down

0 comments on commit 799bc2a

Please sign in to comment.