Browse Source

Adds proper fatal error handling and fixes CLI error reporting.

pull/40/head
jove 8 years ago
parent
commit
f0a625b238
  1. 9
      :q
  2. 25
      inc/error.php
  3. 2
      post.php

9
:q

@ -1,9 +0,0 @@
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch installfix
# Changes to be committed:
# modified: install.php
This prevents a crash due to instance-config.php not existing, it will now check if the file exists and if not creates the file

25
inc/error.php

@ -15,15 +15,32 @@ function exception_handler(Exception $e){
set_exception_handler('exception_handler'); 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']);
}
}
register_shutdown_function('fatal_error_handler');
$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')) {
// Running from CLI
echo('Error: ' . $message . "\n");
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
die();
}
if(!empty($config)){ if(!empty($config)){
if ($config['syslog'] && $priority !== false) { if ($config['syslog'] && $priority !== false) {
@ -31,13 +48,6 @@ function error($message, $priority = true, $debug_stuff = false) {
_syslog($priority !== true ? $priority : LOG_NOTICE, $message); _syslog($priority !== true ? $priority : LOG_NOTICE, $message);
} }
if (defined('STDIN')) {
// Running from CLI
echo('Error: ' . $message . "\n");
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
die();
}
if ($config['debug']) { if ($config['debug']) {
$debug_stuff=array(); $debug_stuff=array();
if(isset($db_error)){ if(isset($db_error)){
@ -55,7 +65,6 @@ function error($message, $priority = true, $debug_stuff = false) {
} }
} }
// Is there a reason to disable this?
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=array('error'=>$message);

2
post.php

@ -325,7 +325,7 @@ if (isset($_POST['delete'])) {
$post['file_tmp'] = tempnam($config['tmp'], 'url'); $post['file_tmp'] = tempnam($config['tmp'], 'url');
function unlink_tmp_file($file) { function unlink_tmp_file($file) {
@unlink($file); @unlink($file);
error(); fatal_error_handler();
} }
register_shutdown_function('unlink_tmp_file', $post['file_tmp']); register_shutdown_function('unlink_tmp_file', $post['file_tmp']);

Loading…
Cancel
Save