- better management of fatal errors (instead of die or trigger_error rather use fatal_error ...)

git-svn-id: http://piwigo.org/svn/trunk@2502 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
rvelices
2008-09-05 01:24:01 +00:00
parent 116f1bc4fb
commit b8a5fde846
8 changed files with 60 additions and 52 deletions
+1 -1
View File
@@ -1832,7 +1832,7 @@ UPDATE '.USER_CACHE_TABLE.'
*/
function create_table_add_character_set($query)
{
defined('DB_CHARSET') or trigger_error('create_table_add_character_set DB_CHARSET undefined', E_USER_ERROR);
defined('DB_CHARSET') or fatal_error('create_table_add_character_set DB_CHARSET undefined');
if ('DB_CHARSET'!='')
{
if ( version_compare(mysql_get_server_info(), '4.1.0', '<') )
+4 -6
View File
@@ -21,10 +21,8 @@
// | USA. |
// +-----------------------------------------------------------------------+
if (!defined('PHPWG_ROOT_PATH'))
{
die('Hacking attempt!');
}
defined('PHPWG_ROOT_PATH') or trigger_error('Hacking attempt!', E_USER_ERROR);
// determine the initial instant to indicate the generation time of this page
$t1 = explode( ' ', microtime() );
$t2 = explode( '.', $t1[0] );
@@ -146,7 +144,7 @@ include(PHPWG_ROOT_PATH . 'include/template.class.php');
@mysql_select_db( $cfgBase ) or my_error( 'mysql_select_db', true );
defined('PWG_CHARSET') and defined('DB_CHARSET')
or die('PWG_CHARSET and/or DB_CHARSET is not defined');
or fatal_error('PWG_CHARSET and/or DB_CHARSET is not defined');
if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') )
{
if (DB_CHARSET!='')
@@ -158,7 +156,7 @@ else
{
if ( strtolower(PWG_CHARSET)!='iso-8859-1' )
{
die('PWG supports only iso-8859-1 charset on MySql version '.mysql_get_server_info());
fatal_error('PWG supports only iso-8859-1 charset on MySql version '.mysql_get_server_info());
}
}
+9 -21
View File
@@ -232,7 +232,7 @@ function mkgetdir($dir, $flags=MKGETDIR_DEFAULT)
umask($umask);
if ($mkd==false)
{
!($flags&MKGETDIR_DIE_ON_ERROR) or trigger_error( "$dir ".l10n('no_write_access'), E_USER_ERROR);
!($flags&MKGETDIR_DIE_ON_ERROR) or fatal_error( "$dir ".l10n('no_write_access'));
return false;
}
if( $flags&MKGETDIR_PROTECT_HTACCESS )
@@ -250,7 +250,7 @@ function mkgetdir($dir, $flags=MKGETDIR_DEFAULT)
{
if ( !is_writable($dir) )
{
!($flags&MKGETDIR_DIE_ON_ERROR) or trigger_error( "$dir ".l10n('no_write_access'), E_USER_ERROR);
!($flags&MKGETDIR_DIE_ON_ERROR) or fatal_error( "$dir ".l10n('no_write_access'));
return false;
}
}
@@ -945,29 +945,17 @@ function get_thumbnail_title($element_info)
// my_error returns (or send to standard output) the message concerning the
// error occured for the last mysql query.
function my_error($header, $die)
{
$error = $header;
$error.= "\n[mysql error ".mysql_errno().'] '.mysql_error()."\n";
if (function_exists('debug_backtrace'))
{
$bt = debug_backtrace();
for ($i=0; $i<count($bt); $i++)
{
$error .= "#$i\t".@$bt[$i]['function']." ".@$bt[$i]['file']."(".@@$bt[$i]['line'].")\n";
}
}
$error = "[mysql error ".mysql_errno().'] '.mysql_error()."\n";
$error .= $header;
if ($die)
{
@set_status_header(500);
echo( str_repeat( ' ', 300)."\n"); //IE doesn't error output if below a size
fatal_error($error);
}
echo("<pre>");
trigger_error($error, $die ? E_USER_ERROR : E_USER_WARNING);
!$die || die($error); // just in case the handler didnt die
trigger_error($error, E_USER_WARNING);
echo("</pre>");
}
@@ -1137,7 +1125,7 @@ function l10n_args($key_args, $sep = "\n")
}
else
{
die('l10n_args: Invalid arguments');
fatal_error('l10n_args: Invalid arguments');
}
return $result;
@@ -1221,7 +1209,7 @@ SELECT param, value
if ((mysql_num_rows($result) == 0) and !empty($condition))
{
die('No configuration data');
fatal_error('No configuration data');
}
while ($row = mysql_fetch_array($result))
@@ -1371,7 +1359,7 @@ function get_filter_page_value($value_name)
*/
function get_pwg_charset()
{
defined('PWG_CHARSET') or die('load_language PWG_CHARSET undefined');
defined('PWG_CHARSET') or fatal_error('load_language PWG_CHARSET undefined');
return PWG_CHARSET;
}
+2 -5
View File
@@ -115,10 +115,7 @@ WHERE id IN (' . implode(',',$page['items']) .')';
$views = array(CAL_VIEW_LIST,CAL_VIEW_CALENDAR);
// Retrieve calendar field
if ( !isset( $fields[ $page['chronology_field'] ] ) )
{
die('bad chronology field');
}
isset( $fields[ $page['chronology_field'] ] ) or fatal_error('bad chronology field');
// Retrieve style
if ( !isset( $styles[ $page['chronology_style'] ] ) )
@@ -198,7 +195,7 @@ WHERE id IN (' . implode(',',$page['items']) .')';
$page['items'] = array();
$must_show_list = false;
}
$page['comment'] = '';
$template->assign('FILE_CHRONOLOGY_VIEW', 'month_calendar.tpl');
+38
View File
@@ -650,6 +650,44 @@ function page_not_found($msg, $alternate_url=null)
5 );
}
/**
* exits the current script with 500 http code
* this method can be called at any time (does not use template/language/user etc...)
* @param string msg a message to display
*/
function fatal_error($msg)
{
$btrace_msg = '';
if (function_exists('debug_backtrace'))
{
$bt = debug_backtrace();
for ($i=1; $i<count($bt); $i++)
{
$class = isset($bt[$i]['class']) ? (@$bt[$i]['class'].'::') : '';
$btrace_msg .= "#$i\t".$class.@$bt[$i]['function'].' '.@$bt[$i]['file']."(".@$bt[$i]['line'].")\n";
}
$btrace_msg = trim($btrace_msg);
$msg .= "\n";
}
$display = "<h1>Piwigo encountered a non recoverable error</h1>
<pre style='font-size:larger;background:white;color:red;padding:1em;margin:0;clear:both;display:block;width:auto;height:auto;overflow:auto'>
<b>$msg</b>
$btrace_msg
</pre>\n";
@set_status_header(500);
echo $display.str_repeat( ' ', 300); //IE doesn't error output if below a size
if ( function_exists('ini_set') )
{// if possible turn off error display (we display it)
ini_set('display_errors', false);
}
error_reporting( E_ALL );
trigger_error( strip_tags($msg).$btrace_msg, E_USER_ERROR );
die(0); // just in case
}
/* returns the title to be displayed above thumbnails on tag page
*/
function get_tags_content_title()
+5 -17
View File
@@ -219,10 +219,8 @@ function duplicate_picture_url($redefined = array(), $removed = array())
function make_picture_url($params)
{
global $conf;
if (!isset($params['image_id']))
{
die('make_picture_url: image_id is a required parameter');
}
isset($params['image_id']) or fatal_error('make_picture_url: image_id is a required parameter');
$url = get_root_url().'picture';
if ($conf['php_extension_in_urls'])
@@ -375,7 +373,7 @@ function make_section_in_url($params)
{
if (!isset($params['tags']) or count($params['tags']) == 0)
{
die('make_section_in_url: require at least one tag');
fatal_error('make_section_in_url: require at least one tag');
}
$section_string.= '/tags';
@@ -406,24 +404,14 @@ function make_section_in_url($params)
}
case 'search' :
{
if (!isset($params['search']))
{
die('make_section_in_url: require a search identifier');
}
isset($params['search']) or fatal_error('make_section_in_url: require a search identifier');
$section_string.= '/search/'.$params['search'];
break;
}
case 'list' :
{
if (!isset($params['list']))
{
die('make_section_in_url: require a list of items');
}
isset($params['list']) or fatal_error('make_section_in_url: require a list of items');
$section_string.= '/list/'.implode(',', $params['list']);
break;
}
case 'none' :
+1 -1
View File
@@ -224,7 +224,7 @@ class Template {
{
if ( !isset($this->files[$handle]) )
{
trigger_error("Template->parse(): Couldn't load template file for handle $handle", E_USER_ERROR);
fatal_error("Template->parse(): Couldn't load template file for handle $handle");
}
$this->smarty->assign( 'ROOT_URL', get_root_url() );
@@ -1 +0,0 @@
*