Commit 64c3d8ab authored by Benni Mack's avatar Benni Mack
Browse files

[BUGFIX] Fix minor error handler code bugs

ErrorHandler has a few minor quirks:

1. the protected property is an integer (bitwise-comparison) but initialized as array
2. small indention and repeatable string introduction
3. human-readable text for E_USER_DEPRECATED missing
4. error handling when no autoloader is available is obsolete.

The patch fixes all these minor issues.

Resolves: #82375
Releases: master, 8.7
Change-Id: Id6f9616602021e04ac6a50737438253a62da788c
Reviewed-on: https://review.typo3.org/54002

Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Helmut Hummel's avatarHelmut Hummel <typo3@helhum.io>
Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent aeb543de
......@@ -28,9 +28,9 @@ class ErrorHandler implements ErrorHandlerInterface
/**
* Error levels which should result in an exception thrown.
*
* @var array
* @var int
*/
protected $exceptionalErrors = [];
protected $exceptionalErrors = 0;
/**
* Whether to write a flash message in case of an error
......@@ -91,38 +91,32 @@ class ErrorHandler implements ErrorHandlerInterface
return true;
}
$errorLevels = [
E_WARNING => 'Warning',
E_NOTICE => 'Notice',
E_USER_ERROR => 'User Error',
E_USER_WARNING => 'User Warning',
E_USER_NOTICE => 'User Notice',
E_STRICT => 'Runtime Notice',
E_RECOVERABLE_ERROR => 'Catchable Fatal Error',
E_DEPRECATED => 'Runtime Deprecation Notice'
E_WARNING => 'PHP Warning',
E_NOTICE => 'PHP Notice',
E_USER_ERROR => 'PHP User Error',
E_USER_WARNING => 'PHP User Warning',
E_USER_NOTICE => 'PHP User Notice',
E_STRICT => 'PHP Runtime Notice',
E_RECOVERABLE_ERROR => 'PHP Catchable Fatal Error',
E_USER_DEPRECATED => 'TYPO3 Deprecation Notice',
E_DEPRECATED => 'PHP Runtime Deprecation Notice'
];
$message = 'PHP ' . $errorLevels[$errorLevel] . ': ' . $errorMessage . ' in ' . $errorFile . ' line ' . $errorLine;
$message = $errorLevels[$errorLevel] . ': ' . $errorMessage . ' in ' . $errorFile . ' line ' . $errorLine;
if ($errorLevel & $this->exceptionalErrors) {
// handle error raised at early parse time
// autoloader not available & built-in classes not resolvable
if (!class_exists('stdClass', false)) {
$message = 'PHP ' . $errorLevels[$errorLevel] . ': ' . $errorMessage . ' in ' . basename($errorFile) .
'line ' . $errorLine;
die($message);
}
throw new Exception($message, 1476107295);
}
switch ($errorLevel) {
case E_USER_ERROR:
case E_RECOVERABLE_ERROR:
$severity = 2;
break;
case E_USER_WARNING:
case E_WARNING:
$severity = 1;
break;
default:
$severity = 0;
}
case E_USER_ERROR:
case E_RECOVERABLE_ERROR:
$severity = 2;
break;
case E_USER_WARNING:
case E_WARNING:
$severity = 1;
break;
default:
$severity = 0;
}
$logTitle = 'Core: Error handler (' . TYPO3_MODE . ')';
$message = $logTitle . ': ' . $message;
// Write error message to the configured syslogs,
......@@ -155,7 +149,7 @@ class ErrorHandler implements ErrorHandlerInterface
$flashMessage = GeneralUtility::makeInstance(
\TYPO3\CMS\Core\Messaging\FlashMessage::class,
$message,
'PHP ' . $errorLevels[$errorLevel],
$errorLevels[$errorLevel],
$severity
);
/** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment