1
0

some more tweaking to the errorToExceptionHandler

This commit is contained in:
Ian
2011-12-08 19:21:24 +01:00
parent e2f60038bb
commit ee116ee460
2 changed files with 39 additions and 17 deletions

View File

@@ -69,32 +69,48 @@ function memSnap($tshow = '') {
/**
* Set our own exeption handler to convert all errors into exeptions automatically
* function_exists() avoids 'cannot redeclare previously declared' fatal errors in XML feed context
* function_exists() avoids 'cannot redeclare previously declared' fatal errors in XML feed context.
*
* See Notes returning false
*
* @access public
* @param standard
* @return null
*/
if(!function_exists('errorToExceptionHandler')) {
function errorToExceptionHandler($errNo, $errStr, $errFile, $errLine, $errContext) {
// ToDo: enhance for special serendipity error needs,
// like $errContext or specify tracing off in user context
// @disabled errors will not appear
function errorToExceptionHandler($errNo, $errStr, $errFile = '', $errLine = NULL, $errContext = array()) {
global $serendipity;
$rep = ini_get('error_reporting');
// function error handler must return false to support $php_errormsg messages
// respect user has set php error_reporting to not display any errors at all
if(!($rep & $errStr)) { return false; }
// respect user has set php to not display errors at all
// may be overridden by if(ini_get('display_errors') == 0) print error in further context
elseif (error_reporting() == 0) { return; }
// throw errors as exception
else {
if($serendipity['production'] !== true) echo ' == DEBUG MODE == ';
// user used @ to specify ignoring all errors or $php_errormsg messages returned with error_reporting = 0
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
if($serendipity['production'] === true && ini_get('display_errors') == 0) { return false; }
// any other errors go here - throw errors as exception
if($serendipity['production'] === 'debug') {
echo '<p> == FULL DEBUG ERROR MODE == </p>';
echo '<pre>';
throw new ErrorException($errStr, 0, $errNo, $errFile, $errLine);
echo '</pre>';
// trying to be as detailled as possible
if(function_exists('debug_backtrace'))
print_r(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)); // whether or not to populate the "object" index >= PHP 5.3.6
throw new ErrorException($errStr); // tracepath = all, if not ini_set('display_errors', 0);
echo '</pre>'; // if throw new ... endtag is not set, but browsers don't care
}
if($serendipity['production'] !== true) {
$e = new Exception;
echo '<p> == TESTING ERROR MODE == </p>';
echo '<pre>';
throw new ErrorException("Serendipity error: " . $errStr); // tracepath = all;
echo '</pre>'; // if throw new ... endtag is not set, , but browsers don't care
} else {
// ToDo: enhance for more special serendipity error needs
$diestr = '<p> == SERENDIPITY ERROR == </p>';
$diestr .= '<p>Please correct:</p>';
$diestr .= '<p>' . $errStr . ' in ' . $errFile . ' on line ' . $errLine . '</p>';
serendipity_die($diestr); // needs to halt with die() here, else will path through and gets written underneath blog content.
}
return true;
}
}

View File

@@ -66,7 +66,13 @@ $serendipity['errorhandler'] = 'errorToExceptionHandler';
//[internal callback function]: errorToExceptionHandler()
if(is_callable($serendipity['errorhandler'], false, $callable_name)) {
// set serendipity global error to exeption handler
set_error_handler($serendipity['errorhandler'], E_ALL & ~E_NOTICE);
#if ($serendipity['production'] === 'debug') {
# set_error_handler($serendipity['errorhandler'], E_ALL);
#} else {
// Caution! If we want to have the same noshow effect as upper set error_reporting(E_ALL) in 'debug' mode,
// do not clone it to set_error_handler(E_ALL), else everythimg is haltet to debug, which makes using debug obsolet.
set_error_handler($serendipity['errorhandler'], E_ALL & ~E_NOTICE);
#}
}
// Default rewrite method