1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-23 23:20:57 +01:00

Better error handling/displaying with $config['debug'] and $config['verbose_errors']

This commit is contained in:
Michael Foster 2013-08-03 00:22:28 -04:00
parent 62f8ea4813
commit 1d37e81ade
5 changed files with 49 additions and 19 deletions

View File

@ -42,7 +42,7 @@
// Shows some extra information at the bottom of pages. Good for development/debugging. // Shows some extra information at the bottom of pages. Good for development/debugging.
$config['debug'] = false; $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; $config['verbose_errors'] = true;
// Directory where temporary files will be created. // Directory where temporary files will be created.

View File

@ -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; global $board, $mod, $config;
if ($config['syslog'] && $priority !== false) { if ($config['syslog'] && $priority !== false) {
@ -74,13 +74,13 @@ function error($message, $priority = true) {
'config' => $config, 'config' => $config,
'title' => _('Error'), 'title' => _('Error'),
'subtitle' => _('An error has occured.'), 'subtitle' => _('An error has occured.'),
'body'=>'<center>' . 'body' => Element('error.html', array(
'<h2>' . _($message) . '</h2>' . 'config' => $config,
(isset($board) ? 'message' => $message,
"<p><a href=\"" . $config['root'] . 'mod' => $mod,
($mod ? $config['file_mod'] . '?/' : '') . 'board' => isset($board) ? $board : false,
$board['dir'] . $config['file_index'] . "\">"._("Go back")."</a>.</p>" : '') . 'debug' => is_array($debug_stuff) ? str_replace("\n", '&#10;', utf8tohtml(print_r($debug_stuff, true))) : utf8tohtml($debug_stuff)
'</center>' ))
))); )));
} }

View File

@ -155,8 +155,20 @@ function loadConfig() {
} }
if ($config['verbose_errors']) { 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); 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 // Keep the original address to properly comply with other board configurations

View File

@ -287,16 +287,16 @@ class ImageConvert extends ImageBase {
if (trim($error = shell_exec("gifsicle --unoptimize -O2 --resize {$this->width}x{$this->height} < " . 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->src . '') . " \"#0-{$config['thumb_keep_animation_frames']}\" > " .
escapeshellarg($this->temp) . '2>&1 &&echo $?') !== '0') || !file_exists($this->temp)) escapeshellarg($this->temp) . '2>&1 &&echo $?') !== '0') || !file_exists($this->temp))
error($error); error('Failed to resize image!', null, $error);
} else { } 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)) escapeshellarg($this->src) . ' ' . escapeshellarg($this->temp) . ' 2>&1 &&echo $?')) !== '0' || !file_exists($this->temp))
error($error); error('Failed to resize image!', null, $error);
} }
} else { } 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)) escapeshellarg($this->src . '[0]') . " " . escapeshellarg($this->temp) . ' 2>&1 &&echo $?')) !== '0' || !file_exists($this->temp))
error($error); error('Failed to resize image!', null, $error);
} }
} }
} }

18
templates/error.html Normal file
View File

@ -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 %}