Changeset 2502


Ignore:
Timestamp:
Sep 5, 2008, 3:24:01 AM (16 years ago)
Author:
rvelices
Message:
  • better management of fatal errors (instead of die or trigger_error rather use fatal_error ...)
Location:
trunk
Files:
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r2495 r2502  
    18331833function create_table_add_character_set($query)
    18341834{
    1835   defined('DB_CHARSET') or trigger_error('create_table_add_character_set DB_CHARSET undefined', E_USER_ERROR);
     1835  defined('DB_CHARSET') or fatal_error('create_table_add_character_set DB_CHARSET undefined');
    18361836  if ('DB_CHARSET'!='')
    18371837  {
  • trunk/include/common.inc.php

    r2488 r2502  
    2222// +-----------------------------------------------------------------------+
    2323
    24 if (!defined('PHPWG_ROOT_PATH'))
    25 {
    26   die('Hacking attempt!');
    27 }
     24defined('PHPWG_ROOT_PATH') or trigger_error('Hacking attempt!', E_USER_ERROR);
     25
    2826// determine the initial instant to indicate the generation time of this page
    2927$t1 = explode( ' ', microtime() );
     
    147145
    148146defined('PWG_CHARSET') and defined('DB_CHARSET')
    149   or die('PWG_CHARSET and/or DB_CHARSET is not defined');
     147  or fatal_error('PWG_CHARSET and/or DB_CHARSET is not defined');
    150148if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') )
    151149{
     
    159157  if ( strtolower(PWG_CHARSET)!='iso-8859-1' )
    160158  {
    161     die('PWG supports only iso-8859-1 charset on MySql version '.mysql_get_server_info());
     159    fatal_error('PWG supports only iso-8859-1 charset on MySql version '.mysql_get_server_info());
    162160  }
    163161}
  • trunk/include/functions.inc.php

    r2497 r2502  
    233233    if ($mkd==false)
    234234    {
    235       !($flags&MKGETDIR_DIE_ON_ERROR) or trigger_error( "$dir ".l10n('no_write_access'), E_USER_ERROR);
     235      !($flags&MKGETDIR_DIE_ON_ERROR) or fatal_error( "$dir ".l10n('no_write_access'));
    236236      return false;
    237237    }
     
    251251    if ( !is_writable($dir) )
    252252    {
    253       !($flags&MKGETDIR_DIE_ON_ERROR) or trigger_error( "$dir ".l10n('no_write_access'), E_USER_ERROR);
     253      !($flags&MKGETDIR_DIE_ON_ERROR) or fatal_error( "$dir ".l10n('no_write_access'));
    254254      return false;
    255255    }
     
    946946// my_error returns (or send to standard output) the message concerning the
    947947// error occured for the last mysql query.
    948 
    949948function my_error($header, $die)
    950949{
    951   $error = $header;
    952   $error.= "\n[mysql error ".mysql_errno().'] '.mysql_error()."\n";
    953 
    954   if (function_exists('debug_backtrace'))
    955   {
    956     $bt = debug_backtrace();
    957     for ($i=0; $i<count($bt); $i++)
    958     {
    959       $error .= "#$i\t".@$bt[$i]['function']." ".@$bt[$i]['file']."(".@@$bt[$i]['line'].")\n";
    960     }
    961   }
     950  $error = "[mysql error ".mysql_errno().'] '.mysql_error()."\n";
     951  $error .= $header;
    962952
    963953  if ($die)
    964954  {
    965     @set_status_header(500);
    966     echo( str_repeat( ' ', 300)."\n"); //IE doesn't error output if below a size
     955    fatal_error($error);
    967956  }
    968957  echo("<pre>");
    969   trigger_error($error, $die ? E_USER_ERROR : E_USER_WARNING);
    970   !$die || die($error); // just in case the handler didnt die
     958  trigger_error($error, E_USER_WARNING);
    971959  echo("</pre>");
    972960}
     
    11381126  else
    11391127  {
    1140     die('l10n_args: Invalid arguments');
     1128    fatal_error('l10n_args: Invalid arguments');
    11411129  }
    11421130
     
    12221210  if ((mysql_num_rows($result) == 0) and !empty($condition))
    12231211  {
    1224     die('No configuration data');
     1212    fatal_error('No configuration data');
    12251213  }
    12261214
     
    13721360function get_pwg_charset()
    13731361{
    1374   defined('PWG_CHARSET') or die('load_language PWG_CHARSET undefined');
     1362  defined('PWG_CHARSET') or fatal_error('load_language PWG_CHARSET undefined');
    13751363  return PWG_CHARSET;
    13761364}
  • trunk/include/functions_calendar.inc.php

    r2299 r2502  
    116116
    117117  // Retrieve calendar field
    118   if ( !isset( $fields[ $page['chronology_field'] ] ) )
    119   {
    120     die('bad chronology field');
    121   }
     118  isset( $fields[ $page['chronology_field'] ] ) or fatal_error('bad chronology field');
    122119
    123120  // Retrieve style
     
    199196      $must_show_list = false;
    200197    }
    201    
     198
    202199    $page['comment'] = '';
    203200    $template->assign('FILE_CHRONOLOGY_VIEW', 'month_calendar.tpl');
  • trunk/include/functions_html.inc.php

    r2488 r2502  
    651651}
    652652
     653/**
     654 * exits the current script with 500 http code
     655 * this method can be called at any time (does not use template/language/user etc...)
     656 * @param string msg a message to display
     657 */
     658function fatal_error($msg)
     659{
     660  $btrace_msg = '';
     661  if (function_exists('debug_backtrace'))
     662  {
     663    $bt = debug_backtrace();
     664    for ($i=1; $i<count($bt); $i++)
     665    {
     666      $class = isset($bt[$i]['class']) ? (@$bt[$i]['class'].'::') : '';
     667      $btrace_msg .= "#$i\t".$class.@$bt[$i]['function'].' '.@$bt[$i]['file']."(".@$bt[$i]['line'].")\n";
     668    }
     669    $btrace_msg = trim($btrace_msg);
     670    $msg .= "\n";
     671  }
     672
     673  $display = "<h1>Piwigo encountered a non recoverable error</h1>
     674<pre style='font-size:larger;background:white;color:red;padding:1em;margin:0;clear:both;display:block;width:auto;height:auto;overflow:auto'>
     675<b>$msg</b>
     676$btrace_msg
     677</pre>\n";
     678
     679  @set_status_header(500);
     680  echo $display.str_repeat( ' ', 300); //IE doesn't error output if below a size
     681
     682  if ( function_exists('ini_set') )
     683  {// if possible turn off error display (we display it)
     684    ini_set('display_errors', false);
     685  }
     686  error_reporting( E_ALL );
     687  trigger_error( strip_tags($msg).$btrace_msg, E_USER_ERROR );
     688  die(0); // just in case
     689}
     690
    653691/* returns the title to be displayed above thumbnails on tag page
    654692 */
  • trunk/include/functions_url.inc.php

    r2299 r2502  
    220220{
    221221  global $conf;
    222   if (!isset($params['image_id']))
    223   {
    224     die('make_picture_url: image_id is a required parameter');
    225   }
     222
     223  isset($params['image_id']) or fatal_error('make_picture_url: image_id is a required parameter');
    226224
    227225  $url = get_root_url().'picture';
     
    376374      if (!isset($params['tags']) or count($params['tags']) == 0)
    377375      {
    378         die('make_section_in_url: require at least one tag');
     376        fatal_error('make_section_in_url: require at least one tag');
    379377      }
    380378
     
    407405    case 'search' :
    408406    {
    409       if (!isset($params['search']))
    410       {
    411         die('make_section_in_url: require a search identifier');
    412       }
    413 
     407      isset($params['search']) or fatal_error('make_section_in_url: require a search identifier');
    414408      $section_string.= '/search/'.$params['search'];
    415 
    416409      break;
    417410    }
    418411    case 'list' :
    419412    {
    420       if (!isset($params['list']))
    421       {
    422         die('make_section_in_url: require a list of items');
    423       }
    424 
     413      isset($params['list']) or fatal_error('make_section_in_url: require a list of items');
    425414      $section_string.= '/list/'.implode(',', $params['list']);
    426 
    427415      break;
    428416    }
  • trunk/include/template.class.php

    r2497 r2502  
    225225    if ( !isset($this->files[$handle]) )
    226226    {
    227       trigger_error("Template->parse(): Couldn't load template file for handle $handle", E_USER_ERROR);
     227      fatal_error("Template->parse(): Couldn't load template file for handle $handle");
    228228    }
    229229
  • trunk/plugins/SwiftThemeCreator/simul

    • Property svn:ignore set to
      *
Note: See TracChangeset for help on using the changeset viewer.