summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Foster <savetheinternet@tinyboard.org>2013-08-03 00:22:28 -0400
committerMichael Foster <savetheinternet@tinyboard.org>2013-08-03 00:22:28 -0400
commit1d37e81adeea9b2a1bc1028f2bf45b47ac045ec4 (patch)
treed4597976f069d51d25768d0fbd16e586947be655
parent62f8ea4813092b42a2cd390a8358ce798d103f40 (diff)
Better error handling/displaying with $config['debug'] and $config['verbose_errors']
-rw-r--r--inc/config.php2
-rw-r--r--inc/display.php22
-rw-r--r--inc/functions.php16
-rw-r--r--inc/image.php10
-rw-r--r--templates/error.html18
5 files changed, 49 insertions, 19 deletions
diff --git a/inc/config.php b/inc/config.php
index 337d92cb..8d1c05d7 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -42,7 +42,7 @@
// Shows some extra information at the bottom of pages. Good for development/debugging.
$config['debug'] = false;
- // For development purposes. All this does is turn 'display_errors' on.
+ // For development purposes. Displays (and "dies" on) all errors and warnings. Turn on with the above.
$config['verbose_errors'] = true;
// Directory where temporary files will be created.
diff --git a/inc/display.php b/inc/display.php
index 7c2665e1..4972d563 100644
--- a/inc/display.php
+++ b/inc/display.php
@@ -57,7 +57,7 @@ function createBoardlist($mod=false) {
);
}
-function error($message, $priority = true) {
+function error($message, $priority = true, $debug_stuff = false) {
global $board, $mod, $config;
if ($config['syslog'] && $priority !== false) {
@@ -71,16 +71,16 @@ function error($message, $priority = true) {
}
die(Element('page.html', array(
- 'config'=>$config,
- 'title'=>_('Error'),
- 'subtitle'=>_('An error has occured.'),
- 'body'=>'<center>' .
- '<h2>' . _($message) . '</h2>' .
- (isset($board) ?
- "<p><a href=\"" . $config['root'] .
- ($mod ? $config['file_mod'] . '?/' : '') .
- $board['dir'] . $config['file_index'] . "\">"._("Go back")."</a>.</p>" : '') .
- '</center>'
+ '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' => is_array($debug_stuff) ? str_replace("\n", '&#10;', utf8tohtml(print_r($debug_stuff, true))) : utf8tohtml($debug_stuff)
+ ))
)));
}
diff --git a/inc/functions.php b/inc/functions.php
index f000dc3c..b6bdd809 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -155,10 +155,22 @@ function loadConfig() {
}
if ($config['verbose_errors']) {
+ set_error_handler(function($errno, $errstr, $errfile, $errline) {
+ if (error_reporting() == 0)
+ return false; // Looks like this warning was suppressed by the @ operator.
+ error(utf8tohtml($errstr), true, array(
+ 'file' => $errfile,
+ 'line' => $errline,
+ 'errno' => $errno,
+ 'error' => $errstr,
+ 'backtrace' => array_slice(debug_backtrace(), 1)
+ ));
+ });
error_reporting(E_ALL);
- ini_set('display_errors', 1);
+ ini_set('display_errors', true);
+ ini_set('html_errors', false);
}
-
+
// Keep the original address to properly comply with other board configurations
if (!isset($__ip))
$__ip = $_SERVER['REMOTE_ADDR'];
diff --git a/inc/image.php b/inc/image.php
index 141973ee..4fc9d018 100644
--- a/inc/image.php
+++ b/inc/image.php
@@ -287,16 +287,16 @@ class ImageConvert extends ImageBase {
if (trim($error = shell_exec("gifsicle --unoptimize -O2 --resize {$this->width}x{$this->height} < " .
escapeshellarg($this->src . '') . " \"#0-{$config['thumb_keep_animation_frames']}\" > " .
escapeshellarg($this->temp) . '2>&1 &&echo $?') !== '0') || !file_exists($this->temp))
- error($error);
+ error('Failed to resize image!', null, $error);
} else {
- if (trim($error = shell_exec('convert ' . sprintf($config['convert_args'], '', $this->width, $this->height) . ' ' .
+ if (trim($error = shell_exec('aconvert ' . sprintf($config['convert_args'], '', $this->width, $this->height) . ' ' .
escapeshellarg($this->src) . ' ' . escapeshellarg($this->temp) . ' 2>&1 &&echo $?')) !== '0' || !file_exists($this->temp))
- error($error);
+ error('Failed to resize image!', null, $error);
}
} else {
- if (trim($error = shell_exec('convert ' . sprintf($config['convert_args'], '-flatten', $this->width, $this->height) . ' ' .
+ if (trim($error = shell_exec('aconvert ' . sprintf($config['convert_args'], '-flatten', $this->width, $this->height) . ' ' .
escapeshellarg($this->src . '[0]') . " " . escapeshellarg($this->temp) . ' 2>&1 &&echo $?')) !== '0' || !file_exists($this->temp))
- error($error);
+ error('Failed to resize image!', null, $error);
}
}
}
diff --git a/templates/error.html b/templates/error.html
new file mode 100644
index 00000000..3b8eb693
--- /dev/null
+++ b/templates/error.html
@@ -0,0 +1,18 @@
+<div style="text-align:center">
+ <h2 style="margin:20px 0">{{ message }}</h2>
+ {% if board %}
+ <p>
+ <a href="{{ config.root }}{% if mod %}{{ config.file_mod }}?/{% endif %}{{ board.dir }}{{ config.file_index }}">
+ {% trans 'Go back' %}
+ </a>
+ </p>
+ {% endif %}
+</div>
+{% if debug and config.debug %}
+ <hr>
+ <h3>{% trans 'Error information' %}</h3>
+ <pre style="white-space:pre-wrap;font-size: 10px;">
+ {{ debug }}
+ </pre>
+ <hr>
+{% endif %} \ No newline at end of file