From af3fb672e3f88ddc2017c2a2758179926da4bc98 Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Fri, 25 Feb 2022 01:49:35 +0100 Subject: [PATCH] Remove errorhandler, let filp/whoops handle them. --- include/compat.inc.php | 189 ------------------------------------- serendipity_config.inc.php | 23 ----- 2 files changed, 212 deletions(-) diff --git a/include/compat.inc.php b/include/compat.inc.php index ac26a1ed..3ac1bb15 100644 --- a/include/compat.inc.php +++ b/include/compat.inc.php @@ -45,195 +45,6 @@ function memSnap($tshow = '') { return '[' . date('d.m.Y H:i') . '] ' . number_format($current - $memUsage, 2, ',', '.') . ' label "' . $tshow . '", totalling ' . number_format($current, 2, ',', '.') . '
' . "\n"; } - -/** - * Make readable error types for debugging error_reporting levels - * - * @access public - * @param int error value - * @return string constant error string - */ -function debug_ErrorLevelType($type) -{ - switch($type) - { - case E_ERROR: // 1 // - return 'E_ERROR'; - case E_WARNING: // 2 // - return 'E_WARNING'; - case E_PARSE: // 4 // - return 'E_PARSE'; - case E_NOTICE: // 8 // - return 'E_NOTICE'; - case E_CORE_ERROR: // 16 // - return 'E_CORE_ERROR'; - case E_CORE_WARNING: // 32 // - return 'E_CORE_WARNING'; - case E_COMPILE_ERROR: // 64 // - return 'E_COMPILE_ERROR'; - case E_COMPILE_WARNING: // 128 // - return 'E_COMPILE_WARNING'; - case E_USER_ERROR: // 256 // - return 'E_USER_ERROR'; - case E_USER_WARNING: // 512 // - return 'E_USER_WARNING'; - case E_USER_NOTICE: // 1024 // - return 'E_USER_NOTICE'; - case E_STRICT: // 2048 // - return 'E_STRICT'; - case E_RECOVERABLE_ERROR: // 4096 // - return 'E_RECOVERABLE_ERROR'; - case E_DEPRECATED: // 8192 // - return 'E_DEPRECATED'; - case E_USER_DEPRECATED: // 16384 // - return 'E_USER_DEPRECATED'; - } - return ""; -} - - -/** - * Set our own exception handler to convert all errors into exceptions automatically - * function_exists() avoids 'cannot redeclare previously declared' fatal errors in XML feed context. - * - * See Notes about returning false - * - * @access public - * @param standard - * @return null - */ -if (!function_exists('errorToExceptionHandler')) { - function errorToExceptionHandler($errNo, $errStr, $errFile = '', $errLine = NULL, $errContext = array()) { - global $serendipity; - - // By default, we will continue our process flow, unless: - $exit = false; - - switch ($errNo) { - case E_ERROR: - case E_USER_ERROR: - $type = 'Fatal Error'; - $exit = true; - break; - - case E_USER_WARNING: - case E_WARNING: - $type = 'Warning'; - break; - - case E_USER_NOTICE: - case E_NOTICE: - case @E_STRICT: - case @E_DEPRECATED: - case @E_USER_DEPRECATED: - $type = 'Notice'; - break; - - case @E_RECOVERABLE_ERROR: - $type = 'Catchable'; - break; - - default: - $type = 'Unknown Error'; - $exit = true; - break; - } - - // NOTE: We do NOT use ini_get('error_reporting'), because that would return the global error reporting, - // and not the one in our current content. @-silenced errors would otherwise never be caught on. - $rep = error_reporting(); - - // Bypass error processing because it's @-silenced. - if ($rep == 0) { - return false; - } - - // if not using Serendipity testing and user or ISP has set PHPs display_errors to show no errors at all, respect this: - if ($serendipity['production'] === true && ini_get('display_errors') == 0) { - return false; - } - - $args = func_get_args(); - - // Several plugins might not adapt to proper style. This should not completely kill our execution. - if ($serendipity['production'] !== 'debug' && preg_match('@Declaration.*should be compatible with@i', $args[1])) { - #if (!headers_sent()) echo "Compatibility warning: Please upgrade file old '{$args[2]}', it contains incompatible signatures.
Details: {$args[1]}
"; - return false; - } - - /* - * $serendipity['production'] can be: - * - * (bool) TRUE: Live-blog, conceal error messages - * (bool) FALSE Beta/alpha builds - * (string) 'debug' Developer build, specifically enabled. - */ - if ($serendipity['production'] !== 'debug') { - $debug_note = '
For more details set $serendipity[\'production\'] = \'debug\' in serendipity_config_local.inc.php to receive a stack-trace.'; - } else { - $debug_note = ''; - } - - // Debug environments shall be verbose... - if ($serendipity['production'] === 'debug') { - echo " == ERROR-REPORT (DEBUGGING ENABLED) ==
\n"; - echo " == (When you copy this debug output to a forum or other places, make sure to remove your username/passwords, as they may be contained within function calls) == \n"; - echo '
';
-            debug_print_backtrace(); // Unlimited output, debugging shall show us everything.
-            echo "
"; - $debug_note = ''; - } elseif ($serendipity['production'] === false) { - echo " == ERROR-REPORT (BETA/ALPHA-BUILDS) == \n"; - } - - if ($serendipity['production'] !== true) { - // Display error (production: FALSE and production: 'debug') - echo '

' . $type . ': '.$errStr . ' in ' . $errFile . ' on line ' . $errLine . '.' . $debug_note . '

'; - - if ($serendipity['production'] === 'debug') { - // In debug mode, throwing an exception here will stop the code execution. Sometimes useful to catch all errors. - throw new \ErrorException($type . ': ' . $errStr, 0, $errNo, $errFile, $errLine); - } - - if (!$serendipity['dbConn'] || $exit) { - exit; // make sure to exit in case of database connection errors or fatal errors. - } - } - } -} - -if (!function_exists('fatalErrorShutdownHandler')) { - /** - * Make fatal Errors readable - * - * @access public - * - * @return string constant error string as Exception - */ - function fatalErrorShutdownHandler() { - $last_error = error_get_last(); - if ($last_error['type'] === E_ERROR) { - // fatal error send to - errorToExceptionHandler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); - } - } -} - -if (!function_exists('file_get_contents')) { - function file_get_contents($filename, $use_include_path = 0) { - $file = fopen($filename, 'rb', $use_include_path); - $data = ''; - if ($file) { - while (!feof($file)) { - $data .= fread($file, 4096); - } - fclose($file); - } - - return $data; - } -} - if (!isset($_REQUEST)) { $_REQUEST = &$HTTP_REQUEST_VARS; } diff --git a/serendipity_config.inc.php b/serendipity_config.inc.php index afac3ab1..6eafafe6 100644 --- a/serendipity_config.inc.php +++ b/serendipity_config.inc.php @@ -295,29 +295,6 @@ if (!is_readable($local_config)) { include($local_config); -if ($serendipity['production'] === 'debug') { - error_reporting(E_ALL ^ E_NOTICE); // is 32759 with 5.4+ -} -if ($serendipity['production'] === false) { - error_reporting(E_ALL & ~(E_NOTICE|E_STRICT)); // is 30711 with 5.4+ -} - -$errLevel = error_reporting(); - -/* [DEBUG] Helper to display current error levels, meant for developers. -echo $errLevel."
\n"; -for ($i = 0; $i < 15; $i++ ) { - print debug_ErrorLevelType($errLevel & pow(2, $i)) . "
\n"; -} -*/ - -// [internal callback function]: errorToExceptionHandler() -if (is_callable($serendipity['errorhandler'], false, $callable_name)) { - // set serendipity global error to exception handler - set_error_handler($serendipity['errorhandler'], $errLevel); // See error_reporting() earlier to see which errors are passed to the handler, deending on $serendipity['production']. - register_shutdown_function('fatalErrorShutdownHandler'); -} - define('IS_up2date', version_compare($serendipity['version'], $serendipity['versionInstalled'], '<=')); // Include main functions