Skip to content

Commit

Permalink
bug #21311 [Debug] Fix fatal error when changing ErrorHandler loggers…
Browse files Browse the repository at this point in the history
… if an exception is buffered (skalpa)

This PR was merged into the 3.2 branch.

Discussion
----------

[Debug] Fix fatal error when changing ErrorHandler loggers if an exception is buffered

| Q             | A
| ------------- | ---
| Branch?       | 3.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #21304
| License       | MIT
| Doc PR        | -

Prevents a fatal error when setting a new logger if the bootstrapping logger buffered an exception that does not extend `ErrorException`.

@nicolas-grekas The faulty behaviour was added by 8f24549, so this PR is against 3.2 and not 2.8.

Commits
-------

a6527f8 [Debug] Fix fatal error when changing ErrorHandler loggers if an exception is buffered
  • Loading branch information
nicolas-grekas committed Jan 16, 2017
2 parents 7a90fcb + a6527f8 commit 87dcda8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Debug/ErrorHandler.php
Expand Up @@ -225,7 +225,7 @@ public function setLoggers(array $loggers)

if ($flush) {
foreach ($this->bootstrappingLogger->cleanLogs() as $log) {
$type = $log[2]['exception']->getSeverity();
$type = $log[2]['exception'] instanceof \ErrorException ? $log[2]['exception']->getSeverity() : E_ERROR;
if (!isset($flush[$type])) {
$this->bootstrappingLogger->log($log[0], $log[1], $log[2]);
} elseif ($this->loggers[$type][0]) {
Expand Down
19 changes: 19 additions & 0 deletions src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php
Expand Up @@ -417,6 +417,25 @@ public function testBootstrappingLogger()
$handler->setLoggers(array(E_DEPRECATED => array($mockLogger, LogLevel::WARNING)));
}

public function testSettingLoggerWhenExceptionIsBuffered()
{
$bootLogger = new BufferingLogger();
$handler = new ErrorHandler($bootLogger);

$exception = new \Exception('Foo message');

$mockLogger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$mockLogger->expects($this->once())
->method('log')
->with(LogLevel::CRITICAL, 'Uncaught Exception: Foo message', array('exception' => $exception));

$handler->setExceptionHandler(function () use ($handler, $mockLogger) {
$handler->setDefaultLogger($mockLogger);
});

$handler->handleException($exception);
}

public function testHandleFatalError()
{
try {
Expand Down

0 comments on commit 87dcda8

Please sign in to comment.