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:
parent
62f8ea4813
commit
1d37e81ade
@ -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.
|
||||
|
@ -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) {
|
||||
@ -74,13 +74,13 @@ function error($message, $priority = true) {
|
||||
'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>'
|
||||
'body' => Element('error.html', array(
|
||||
'config' => $config,
|
||||
'message' => $message,
|
||||
'mod' => $mod,
|
||||
'board' => isset($board) ? $board : false,
|
||||
'debug' => is_array($debug_stuff) ? str_replace("\n", ' ', utf8tohtml(print_r($debug_stuff, true))) : utf8tohtml($debug_stuff)
|
||||
))
|
||||
)));
|
||||
}
|
||||
|
||||
|
@ -155,8 +155,20 @@ 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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
18
templates/error.html
Normal file
18
templates/error.html
Normal 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 %}
|
Loading…
Reference in New Issue
Block a user