forked from leftypol/leftypol
error.php: format
This commit is contained in:
parent
4e1654a1d3
commit
86266bb98a
1 changed files with 22 additions and 23 deletions
|
@ -1,22 +1,22 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
function error_handler($errno, $errstr, $errfile, $errline) {
|
function error_handler($errno, $errstr, $errfile, $errline) {
|
||||||
if(error_reporting() & $errno){
|
if (error_reporting() & $errno) {
|
||||||
$config['debug']=true;
|
$config['debug'] = true;
|
||||||
error($errstr . ' in ' . $errfile . ' at line ' . $errline);
|
error("$errstr in $errfile at line $errline");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function exception_handler($e){
|
function exception_handler($e) {
|
||||||
error($e->getMessage());
|
error($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
set_exception_handler('exception_handler');
|
set_exception_handler('exception_handler');
|
||||||
|
|
||||||
function fatal_error_handler(){
|
function fatal_error_handler() {
|
||||||
if (($error = error_get_last()) && $error['type'] == E_ERROR) {
|
if (($error = error_get_last()) && $error['type'] == E_ERROR) {
|
||||||
error('Caught fatal error: ' . $error['message'] . ' in ' . $error['file'] . ' at line ' . $error['line']);
|
error("Caught fatal error: {$error['message']} in {$error['file']} at line {$error['line']}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,35 +24,34 @@ register_shutdown_function('fatal_error_handler');
|
||||||
|
|
||||||
// Due to composer autoload, this isn't implicitly global anymore
|
// Due to composer autoload, this isn't implicitly global anymore
|
||||||
global $error_recursion;
|
global $error_recursion;
|
||||||
$error_recursion=false;
|
$error_recursion = false;
|
||||||
|
|
||||||
function error($message, $priority = true, $debug_stuff = false) {
|
function error($message, $priority = true, $debug_stuff = false) {
|
||||||
global $board, $mod, $config, $db_error, $error_recursion;
|
global $board, $mod, $config, $db_error, $error_recursion;
|
||||||
|
|
||||||
if($error_recursion!==false){
|
if($error_recursion !== false) {
|
||||||
die("Error recursion detected with " . $message . "<br>Original error:".$error_recursion);
|
die("Error recursion detected with $message<br>Original error: $error_recursion");
|
||||||
}
|
}
|
||||||
|
|
||||||
$error_recursion=$message;
|
$error_recursion = $message;
|
||||||
|
|
||||||
if (defined('STDIN')) {
|
if (defined('STDIN')) {
|
||||||
// Running from CLI
|
// Running from CLI
|
||||||
echo('Error: ' . $message . "\n");
|
echo("Error: $message\n");
|
||||||
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($config)){
|
if (!empty($config)) {
|
||||||
|
|
||||||
if ($config['syslog'] && $priority !== false) {
|
if ($config['syslog'] && $priority !== false) {
|
||||||
// Use LOG_NOTICE instead of LOG_ERR or LOG_WARNING because most error message are not significant.
|
// Use LOG_NOTICE instead of LOG_ERR or LOG_WARNING because most error message are not significant.
|
||||||
_syslog($priority !== true ? $priority : LOG_NOTICE, $message);
|
_syslog($priority !== true ? $priority : LOG_NOTICE, $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($config['debug']) {
|
if ($config['debug']) {
|
||||||
$debug_stuff=array();
|
$debug_stuff = [];
|
||||||
if(isset($db_error)){
|
if (isset($db_error)) {
|
||||||
$debug_stuff = array_combine(array('SQLSTATE', 'Error code', 'Error message'), $db_error);
|
$debug_stuff = array_combine([ 'SQLSTATE', 'Error code', 'Error message' ], $db_error);
|
||||||
}
|
}
|
||||||
$debug_stuff['backtrace'] = debug_backtrace();
|
$debug_stuff['backtrace'] = debug_backtrace();
|
||||||
$pw = $config['db']['password'];
|
$pw = $config['db']['password'];
|
||||||
|
@ -60,7 +59,7 @@ function error($message, $priority = true, $debug_stuff = false) {
|
||||||
if (is_array($item)) {
|
if (is_array($item)) {
|
||||||
$item = array_filter($item, $debug_callback);
|
$item = array_filter($item, $debug_callback);
|
||||||
}
|
}
|
||||||
return ($item !== $pw || !$pw);
|
return $item !== $pw || !$pw;
|
||||||
};
|
};
|
||||||
$debug_stuff = array_map($debug_callback, $debug_stuff);
|
$debug_stuff = array_map($debug_callback, $debug_stuff);
|
||||||
}
|
}
|
||||||
|
@ -68,17 +67,17 @@ function error($message, $priority = true, $debug_stuff = false) {
|
||||||
|
|
||||||
if (isset($_POST['json_response'])) {
|
if (isset($_POST['json_response'])) {
|
||||||
header('Content-Type: text/json; charset=utf-8');
|
header('Content-Type: text/json; charset=utf-8');
|
||||||
$data=array('error'=>$message);
|
$data = [ 'error' => $message ];
|
||||||
if(!empty($config) && $config['debug']){
|
if (!empty($config) && $config['debug']) {
|
||||||
$data['debug']=$debug_stuff;
|
$data['debug'] = $debug_stuff;
|
||||||
}
|
}
|
||||||
print json_encode($data);
|
print json_encode($data);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error');
|
header("{$_SERVER['SERVER_PROTOCOL']} 500 Internal Server Error");
|
||||||
|
|
||||||
die(Element('page.html', array(
|
die(Element('page.html', [
|
||||||
'config' => $config,
|
'config' => $config,
|
||||||
'title' => _('Error'),
|
'title' => _('Error'),
|
||||||
'subtitle' => _('An error has occured.'),
|
'subtitle' => _('An error has occured.'),
|
||||||
|
@ -89,5 +88,5 @@ function error($message, $priority = true, $debug_stuff = false) {
|
||||||
'board' => isset($board) ? $board : false,
|
'board' => isset($board) ? $board : false,
|
||||||
'debug' => str_replace("\n", ' ', utf8tohtml(print_r($debug_stuff, true)))
|
'debug' => str_replace("\n", ' ', utf8tohtml(print_r($debug_stuff, true)))
|
||||||
))
|
))
|
||||||
)));
|
]));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue