diff --git a/inc/error.php b/inc/error.php index fbab934d..de69db35 100644 --- a/inc/error.php +++ b/inc/error.php @@ -1,23 +1,23 @@ getMessage()); + error($e->getMessage()); } set_exception_handler('exception_handler'); function fatal_error_handler(){ - if (($error = error_get_last()) && $error['type'] == E_ERROR) { - error('Caught fatal error: ' . $error['message'] . ' in ' . $error['file'] . ' at line ' . $error['line']); - } + if (($error = error_get_last()) && $error['type'] == E_ERROR) { + error('Caught fatal error: ' . $error['message'] . ' in ' . $error['file'] . ' at line ' . $error['line']); + } } register_shutdown_function('fatal_error_handler'); @@ -25,37 +25,37 @@ register_shutdown_function('fatal_error_handler'); $error_recursion=false; function error($message, $priority = true, $debug_stuff = false) { - global $board, $mod, $config, $db_error, $error_recursion; - - if($error_recursion!==false){ - die("Error recursion detected with " . $message . "
Original error:".$error_recursion); - } - - $error_recursion=$message; - - if (defined('STDIN')) { - // Running from CLI - echo('Error: ' . $message . "\n"); - debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); - die(); - } - - if(!empty($config)){ - - if ($config['syslog'] && $priority !== false) { - // Use LOG_NOTICE instead of LOG_ERR or LOG_WARNING because most error message are not significant. - _syslog($priority !== true ? $priority : LOG_NOTICE, $message); - } + global $board, $mod, $config, $db_error, $error_recursion; - if ($config['debug']) { - $debug_stuff=array(); + if($error_recursion!==false){ + die("Error recursion detected with " . $message . "
Original error:".$error_recursion); + } - if (isset($db_error)){ - $debug_stuff = array_combine(array('SQLSTATE', 'Error code', 'Error message'), $db_error); - } + $error_recursion=$message; - $debug_stuff['backtrace'] = debug_backtrace(); - $pw = $config['db']['password']; + if (defined('STDIN')) { + // Running from CLI + echo('Error: ' . $message . "\n"); + debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); + die(); + } + + if(!empty($config)){ + + if ($config['syslog'] && $priority !== false) { + // Use LOG_NOTICE instead of LOG_ERR or LOG_WARNING because most error message are not significant. + _syslog($priority !== true ? $priority : LOG_NOTICE, $message); + } + + if ($config['debug']) { + $debug_stuff=array(); + + if (isset($db_error)){ + $debug_stuff = array_combine(array('SQLSTATE', 'Error code', 'Error message'), $db_error); + } + + $debug_stuff['backtrace'] = debug_backtrace(); + $pw = $config['db']['password']; $debug_callback = function ($item) use (&$debug_callback, $pw) { if (is_array($item)) { @@ -64,32 +64,32 @@ function error($message, $priority = true, $debug_stuff = false) { return ($item == $pw ? 'hunter2' : $item); }; - $debug_stuff = array_map($debug_callback, $debug_stuff); - } - } + $debug_stuff = array_map($debug_callback, $debug_stuff); + } + } - if (isset($_POST['json_response'])) { - header('Content-Type: text/json; charset=utf-8'); - $data=array('error'=>$message); - if(!empty($config) && $config['debug']){ - $data['debug']=$debug_stuff; - } - print json_encode($data); - exit(); - } + if (isset($_POST['json_response'])) { + header('Content-Type: text/json; charset=utf-8'); + $data=array('error'=>$message); + if(!empty($config) && $config['debug']){ + $data['debug']=$debug_stuff; + } + print json_encode($data); + exit(); + } - header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error'); - - die(Element('page.html', array( - 'config' => $config, - 'title' => _('Error'), - 'subtitle' => _('An error has occured.'), - 'body' => Element('error.html', array( - 'config' => $config, - 'message' => $message, - 'mod' => $mod, - 'board' => isset($board) ? $board : false, - 'debug' => str_replace("\n", ' ', utf8tohtml(print_r($debug_stuff, true))) - )) - ))); + header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error'); + + die(Element('page.html', array( + 'config' => $config, + 'title' => _('Error'), + 'subtitle' => _('An error has occured.'), + 'body' => Element('error.html', array( + 'config' => $config, + 'message' => $message, + 'mod' => $mod, + 'board' => isset($board) ? $board : false, + 'debug' => str_replace("\n", ' ', utf8tohtml(print_r($debug_stuff, true))) + )) + ))); }