Skip to content

Commit a6527f8

Browse files
author
skalpa
committed
[Debug] Fix fatal error when changing ErrorHandler loggers if an exception is buffered
1 parent 7a90fcb commit a6527f8

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Symfony/Component/Debug/ErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public function setLoggers(array $loggers)
225225

226226
if ($flush) {
227227
foreach ($this->bootstrappingLogger->cleanLogs() as $log) {
228-
$type = $log[2]['exception']->getSeverity();
228+
$type = $log[2]['exception'] instanceof \ErrorException ? $log[2]['exception']->getSeverity() : E_ERROR;
229229
if (!isset($flush[$type])) {
230230
$this->bootstrappingLogger->log($log[0], $log[1], $log[2]);
231231
} elseif ($this->loggers[$type][0]) {

src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,25 @@ public function testBootstrappingLogger()
417417
$handler->setLoggers(array(E_DEPRECATED => array($mockLogger, LogLevel::WARNING)));
418418
}
419419

420+
public function testSettingLoggerWhenExceptionIsBuffered()
421+
{
422+
$bootLogger = new BufferingLogger();
423+
$handler = new ErrorHandler($bootLogger);
424+
425+
$exception = new \Exception('Foo message');
426+
427+
$mockLogger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
428+
$mockLogger->expects($this->once())
429+
->method('log')
430+
->with(LogLevel::CRITICAL, 'Uncaught Exception: Foo message', array('exception' => $exception));
431+
432+
$handler->setExceptionHandler(function () use ($handler, $mockLogger) {
433+
$handler->setDefaultLogger($mockLogger);
434+
});
435+
436+
$handler->handleException($exception);
437+
}
438+
420439
public function testHandleFatalError()
421440
{
422441
try {

0 commit comments

Comments
 (0)