Skip to content
Snippets Groups Projects
Commit 570d512f authored by Markus Klein's avatar Markus Klein Committed by Wouter Wolters
Browse files

[TASK] Cleanup error handling code and settings description

The error handling code for PHP errors needs some cleanup.
So does the description of the related settings in the Install Tool.

Resolves: #61235
Releases: 6.3, 6.2
Change-Id: Ibd95fcdaa6a50a870035037a2332b95d2c5e1266
Reviewed-on: http://review.typo3.org/32464


Reviewed-by: default avatarAlexander Opitz <opitz.alexander@googlemail.com>
Tested-by: default avatarAlexander Opitz <opitz.alexander@googlemail.com>
Reviewed-by: default avatarViktor Livakivskyi <invisible.kinder@gmail.com>
Tested-by: default avatarViktor Livakivskyi <invisible.kinder@gmail.com>
Reviewed-by: default avatarWouter Wolters <typo3@wouterwolters.nl>
Tested-by: default avatarWouter Wolters <typo3@wouterwolters.nl>
parent 071a7f47
Branches
Tags
No related merge requests found
......@@ -582,25 +582,23 @@ class Bootstrap {
protected function configureExceptionHandling() {
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['productionExceptionHandler'];
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['exceptionalErrors'];
$doesIpMatch = Utility\GeneralUtility::cmpIP(Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask']);
$displayErrors = (int)$GLOBALS['TYPO3_CONF_VARS']['SYS']['displayErrors'];
// Turn error logging on/off.
if (($displayErrors = (int)$GLOBALS['TYPO3_CONF_VARS']['SYS']['displayErrors']) != '-1') {
if ($displayErrors !== -1) {
// Special value "2" enables this feature only if $GLOBALS['TYPO3_CONF_VARS'][SYS][devIPmask] matches
if ($displayErrors == 2) {
if (Utility\GeneralUtility::cmpIP(Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
$displayErrors = 1;
} else {
$displayErrors = 0;
}
if ($displayErrors === 2) {
$displayErrors = (int)$doesIpMatch;
}
if ($displayErrors == 0) {
if ($displayErrors === 0) {
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors'] = 0;
}
if ($displayErrors == 1) {
if ($displayErrors === 1) {
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'];
define('TYPO3_ERRORHANDLER_MODE', 'debug');
}
@ini_set('display_errors', $displayErrors);
} elseif (Utility\GeneralUtility::cmpIP(Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
} elseif ($doesIpMatch) {
// With displayErrors = -1 (default), turn on debugging if devIPmask matches:
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'];
}
......
......@@ -111,7 +111,7 @@ abstract class AbstractExceptionHandler implements ExceptionHandlerInterface, \T
'error' => 2,
'details_nr' => 0,
'details' => str_replace('%', '%%', $logMessage),
'IP' => GeneralUtility::getIndpEnv('REMOTE_ADDR'),
'IP' => (string)GeneralUtility::getIndpEnv('REMOTE_ADDR'),
'tstamp' => $GLOBALS['EXEC_TIME'],
'workspace' => $workspace
);
......
......@@ -22,7 +22,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
*
* @author Rupert Germann <rupi@gmx.li>
*/
class ErrorHandler implements \TYPO3\CMS\Core\Error\ErrorHandlerInterface {
class ErrorHandler implements ErrorHandlerInterface {
/**
* Error levels which should result in an exception thrown.
......@@ -56,7 +56,7 @@ class ErrorHandler implements \TYPO3\CMS\Core\Error\ErrorHandlerInterface {
/**
* Handles an error.
* If the error is registered as exceptionalError it will by converted into an exception, to be handled
* by the configured exceptionhandler. Additionall the error message is written to the configured logs.
* by the configured exceptionhandler. Additionally the error message is written to the configured logs.
* If TYPO3_MODE is 'BE' the error message is also added to the flashMessageQueue, in FE the error message
* is displayed in the admin panel (as TsLog message)
*
......@@ -65,11 +65,11 @@ class ErrorHandler implements \TYPO3\CMS\Core\Error\ErrorHandlerInterface {
* @param string $errorFile Name of the file the error occurred in
* @param int $errorLine Line number where the error occurred
* @return bool
* @throws \TYPO3\CMS\Core\Error\Exception with the data passed to this method if the error is registered as exceptionalError
* @throws Exception with the data passed to this method if the error is registered as exceptionalError
*/
public function handleError($errorLevel, $errorMessage, $errorFile, $errorLine) {
// Don't do anything if error_reporting is disabled by an @ sign
if (error_reporting() == 0) {
if (error_reporting() === 0) {
return TRUE;
}
$errorLevels = array(
......@@ -84,8 +84,8 @@ class ErrorHandler implements \TYPO3\CMS\Core\Error\ErrorHandlerInterface {
);
$message = 'PHP ' . $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
// 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;
......@@ -98,7 +98,7 @@ class ErrorHandler implements \TYPO3\CMS\Core\Error\ErrorHandlerInterface {
require_once PATH_site . 'typo3/sysext/core/Classes/Exception.php';
require_once PATH_site . 'typo3/sysext/core/Classes/Error/Exception.php';
}
throw new \TYPO3\CMS\Core\Error\Exception($message, 1);
throw new Exception($message, 1);
} else {
switch ($errorLevel) {
case E_USER_ERROR:
......@@ -140,6 +140,7 @@ class ErrorHandler implements \TYPO3\CMS\Core\Error\ErrorHandlerInterface {
}
// Add error message to the flashmessageQueue
if (defined('TYPO3_ERRORHANDLER_MODE') && TYPO3_ERRORHANDLER_MODE == 'debug') {
/** @var $flashMessage \TYPO3\CMS\Core\Messaging\FlashMessage */
$flashMessage = GeneralUtility::makeInstance(
'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
$message,
......@@ -161,7 +162,7 @@ class ErrorHandler implements \TYPO3\CMS\Core\Error\ErrorHandlerInterface {
* Writes an error in the sys_log table
*
* @param string $logMessage Default text that follows the message (in english!).
* @param int $severity The eror level of the message (0 = OK, 1 = warning, 2 = error)
* @param int $severity The error level of the message (0 = OK, 1 = warning, 2 = error)
* @return void
*/
protected function writeLog($logMessage, $severity) {
......
......@@ -39,7 +39,7 @@ interface ErrorHandlerInterface {
/**
* Handles an error.
* If the error is registered as exceptionalError it will by converted into an exception, to be handled
* by the configured exceptionhandler. Additionall the error message is written to the configured logs.
* by the configured exceptionhandler. Additionally the error message is written to the configured logs.
* If TYPO3_MODE is 'BE' the error message is also added to the flashMessageQueue, in FE the error message
* is displayed in the admin panel (as TsLog message)
*
......
......@@ -206,12 +206,12 @@ return array(
),
),
'defaultCategorizedTables' => 'pages,tt_content,sys_file_metadata', // List of comma separated tables that are categorizable by default.
'displayErrors' => -1, // <p>Integer (-1, 0, 1, 2). Configures whether PHP errors should be displayed.</p><dl><dt>0</dt><dd>Do not display any PHP error messages. Overrides the value of "exceptionalErrors" and sets it to 0 (= no errors are turned into exceptions), the configured "productionExceptionHandler" is used as exception handler</dd><dt>1</dt><dd>Display error messages with the registered errorhandler. The configured "debugExceptionHandler" is used as exception handler</dd><dt>2</dt><dd>Display errors only if client matches <a href="#SYS-devIPmask">[SYS][devIPmask]</a>. If devIPmask matches the users IP address the configured "debugExceptionHandler" is used for exceptions, if not "productionExceptionHandler" will be used</dd><dt>-1</dt><dd>Default setting. With this option, you can override the PHP setting "display_errors". If devIPmask matches the users IP address the configured "debugExceptionHandler" is used for exceptions, if not "productionExceptionHandler" will be used.</dd></dl>
'productionExceptionHandler' => 'TYPO3\\CMS\\Core\\Error\\ProductionExceptionHandler', // String: Classname to handle exceptions that might happen in the TYPO3-code. Leave empty to disable exception handling. Default: "TYPO3\\CMS\\Core\\Error\\ProductionExceptionHandler". This exception handler displays a nice error message when something went wrong. The error message is logged to the configured logs. Note: The configured "productionExceptionHandler" is used if displayErrors is set to "0" or to "-1" and devIPmask doesn't match the users IP.
'debugExceptionHandler' => 'TYPO3\\CMS\\Core\\Error\\DebugExceptionHandler', // String: Classname to handle exceptions that might happen in the TYPO3-code. Leave empty to disable exception handling. Default: "TYPO3\\CMS\\Core\\Error\\DebugExceptionHandler". This exception handler displays the complete stack trace of any encountered exception. The error message and the stack trace is logged to the configured logs. Note: The configured "debugExceptionHandler" is used if displayErrors is set to "1" and if displayErrors is "-1" or "2" and the devIPmask matches the users IP.
'errorHandler' => 'TYPO3\\CMS\\Core\\Error\\ErrorHandler', // String: Classname to handle PHP errors. E.g.: t3lib_error_ErrorHandler. This class displays and logs all errors that are registered as "errorHandlerErrors" (<a href="#SYS-errorHandlerErrors">[SYS][errorHandlerErrors]</a>). Leave empty to disable error handling. Errors can be logged to syslog (see: <a href="#SYS-systemLog">[SYS][systemLog]</a>) to the installed developer log and to the "syslog" table. If an error is registered in "exceptionalErrors" ([SYS][exceptionalErrors]) it will be turned into an exception to be handled by the configured exceptionHandler.
'errorHandlerErrors' => E_ALL & ~(E_STRICT | E_NOTICE | E_COMPILE_WARNING | E_COMPILE_ERROR | E_CORE_WARNING | E_CORE_ERROR | E_PARSE | E_ERROR), // Integer: The E_* constant that will be handled by the errorhandler. Not all PHP error types can be handled! Default is <code>E_ALL & ~(E_STRICT | E_NOTICE | E_COMPILE_WARNING | E_COMPILE_ERROR | E_CORE_WARNING | E_CORE_ERROR | E_PARSE | E_ERROR)</code>.
'exceptionalErrors' => E_ALL & ~(E_STRICT | E_NOTICE | E_COMPILE_WARNING | E_COMPILE_ERROR | E_CORE_WARNING | E_CORE_ERROR | E_PARSE | E_ERROR | E_DEPRECATED | E_WARNING | E_USER_ERROR | E_USER_NOTICE | E_USER_WARNING), // Integer: The E_* constant that will be handled as an exception by TYPO3\\CMS\\Core\\Error\\ErrorHandler. Default is <code>E_ALL & ~(E_STRICT | E_NOTICE | E_COMPILE_WARNING | E_COMPILE_ERROR | E_CORE_WARNING | E_CORE_ERROR | E_PARSE | E_ERROR | E_DEPRECATED | E_WARNING | E_USER_ERROR | E_USER_NOTICE | E_USER_WARNING)</code> (see <a href="http://php.net/manual/en/errorfunc.constants.php" target="_blank">PHP documentation</a>).
'displayErrors' => -1, // <p>Integer (-1, 0, 1, 2). Configures whether PHP errors or Exceptions should be displayed.</p><dl><dt>0</dt><dd>Do not display any PHP error message. Sets PHP "display_errors" setting to 0. Overrides the value of [SYS][exceptionalErrors] and sets it to 0 (= no errors are turned into exceptions). The configured [SYS][productionExceptionHandler] is used as exception handler.</dd><dt>1</dt><dd>Display error messages with the registered [SYS][errorHandler]. Sets PHP "display_errors" setting to 1. The configured [SYS][debugExceptionHandler] is used as exception handler.</dd><dt>2</dt><dd>Lets the [SYS][devIPmask] decide if this setting shall be "1" (user's IP matches) or "0" (IP does not match).</dd><dt>-1</dt><dd>Default setting. TYPO3 CMS does not touch the PHP "display_errors" setting. If [SYS][devIPmask] matches the user's IP address, the configured [SYS][debugExceptionHandler] is used instead of the [SYS][productionExceptionHandler] to handle exceptions.</dd></dl>
'productionExceptionHandler' => 'TYPO3\\CMS\\Core\\Error\\ProductionExceptionHandler', // String: Classname to handle exceptions that might happen in the TYPO3-code. Leave empty to disable exception handling. Default: "TYPO3\\CMS\\Core\\Error\\ProductionExceptionHandler". This exception handler displays a nice error message when something went wrong. The error message is logged to the configured logs. Note: The configured "productionExceptionHandler" is used if [SYS][displayErrors] is set to "0" or is set to "-1" and [SYS][devIPmask] doesn't match the user's IP.
'debugExceptionHandler' => 'TYPO3\\CMS\\Core\\Error\\DebugExceptionHandler', // String: Classname to handle exceptions that might happen in the TYPO3-code. Leave empty to disable exception handling. Default: "TYPO3\\CMS\\Core\\Error\\DebugExceptionHandler". This exception handler displays the complete stack trace of any encountered exception. The error message and the stack trace is logged to the configured logs. Note: The configured "debugExceptionHandler" is used if [SYS][displayErrors] is set to "1" or is set to "-1" or "2" and the [SYS][devIPmask] matches the user's IP.
'errorHandler' => 'TYPO3\\CMS\\Core\\Error\\ErrorHandler', // String: Classname to handle PHP errors. E.g.: TYPO3\CMS\Core\Error\ErrorHandler. This class displays and logs all errors that are registered as [SYS][errorHandlerErrors]. Leave empty to disable error handling. Errors can be logged to syslog (see: [SYS][systemLog]), to the installed developer log and to the "syslog" table. If an error is registered in [SYS][exceptionalErrors] it will be turned into an exception to be handled by the configured exceptionHandler.
'errorHandlerErrors' => E_ALL & ~(E_STRICT | E_NOTICE | E_COMPILE_WARNING | E_COMPILE_ERROR | E_CORE_WARNING | E_CORE_ERROR | E_PARSE | E_ERROR), // Integer: The E_* constant that will be handled by the [SYS][errorHandler]. Not all PHP error types can be handled! Default is <code>E_ALL & ~(E_STRICT | E_NOTICE | E_COMPILE_WARNING | E_COMPILE_ERROR | E_CORE_WARNING | E_CORE_ERROR | E_PARSE | E_ERROR)</code>.
'exceptionalErrors' => E_ALL & ~(E_STRICT | E_NOTICE | E_COMPILE_WARNING | E_COMPILE_ERROR | E_CORE_WARNING | E_CORE_ERROR | E_PARSE | E_ERROR | E_DEPRECATED | E_WARNING | E_USER_ERROR | E_USER_NOTICE | E_USER_WARNING), // Integer: The E_* constant that will be converted into an exception by the default [SYS][errorHandler]. Default is <code>E_ALL & ~(E_STRICT | E_NOTICE | E_COMPILE_WARNING | E_COMPILE_ERROR | E_CORE_WARNING | E_CORE_ERROR | E_PARSE | E_ERROR | E_DEPRECATED | E_WARNING | E_USER_ERROR | E_USER_NOTICE | E_USER_WARNING)</code> (see <a href="http://php.net/manual/en/errorfunc.constants.php" target="_blank">PHP documentation</a>).
'enable_errorDLOG' => 0, // Boolean: If set, errors are written to the developer log (requires an installed *devlog* extension).
'enable_exceptionDLOG' => 0,// Boolean: If set, exceptions are written to the developer log (requires an installed *devlog* extension).
'syslogErrorReporting' => E_ALL & ~(E_STRICT | E_NOTICE), // Integer: Configures which PHP errors should be logged to the configured syslogs (see: [SYS][systemLog]). If set to "0" no PHP errors are logged to the syslog. Default is "E_ALL & ~(E_STRICT | E_NOTICE)" (22519).
......
......@@ -38,7 +38,7 @@ class DevelopmentPreset extends Configuration\AbstractPreset {
'BE/debug' => TRUE,
'FE/debug' => TRUE,
'SYS/devIPmask' => '*',
'SYS/displayErrors' => TRUE,
'SYS/displayErrors' => 1,
'SYS/enableDeprecationLog' => 'file',
'SYS/sqlDebug' => 1,
'SYS/systemLogLevel' => 0,
......
......@@ -38,7 +38,7 @@ class ProductionPreset extends Configuration\AbstractPreset {
'BE/debug' => FALSE,
'FE/debug' => FALSE,
'SYS/devIPmask' => '',
'SYS/displayErrors' => FALSE,
'SYS/displayErrors' => 0,
'SYS/enableDeprecationLog' => FALSE,
'SYS/sqlDebug' => 0,
'SYS/systemLogLevel' => 2,
......
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