Debug backtrace on all errors when go_debug is set to 2
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Thu, 9 Dec 2010 11:07:41 +0000 (11:07 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Thu, 9 Dec 2010 11:07:41 +0000 (11:07 +0000)
includes/errors.inc
includes/ui/ui_msgs.inc
includes/ui/ui_view.inc

index bcb3cd3f99e1b064257a74352f2c890d2e64959a..f55951cf4652c1cc69d4f8f0a2bb0c070fc71626 100644 (file)
@@ -29,8 +29,9 @@ function error_handler($errno, $errstr, $file, $line) {
        }
        
        // error_reporting==0 when messages are set off with @ 
-       if ($errno & error_reporting())
-                       $messages[] = array($errno, $errstr, $file, $line);
+       if ($errno & error_reporting()) {
+               $messages[] = array($errno, $errstr, $file, $line);
+       }
        else if($errno&~E_NOTICE) { // log all not displayed messages 
                $user = @$_SESSION["wa_current_user"]->loginname;
                $context = isset($SysPrefs) && !$SysPrefs->db_ok ? '[before upgrade]' : '';
@@ -131,7 +132,7 @@ function display_db_error($msg, $sql_statement=null, $exit=true)
                $cur_prefix = $db_connections[$_SESSION["wa_current_user"]->cur_con]['tbpref'];
 
                $str .= "sql that failed was : ".str_replace(TB_PREF, $cur_prefix, $sql_statement)."<br>";
-               if ($go_debug > 1) display_backtrace();
+//             if ($go_debug > 1) display_backtrace();
        }
        
        $str .= "<br><br>";
index 8925c030ba4954248e3f88cb9f4876e936281d23..5c28c8939ba5d65ef3a25f3e89fd182b8e6efaea 100644 (file)
 ***********************************************************************/
 function display_error($msg, $center=true)
 {
-       trigger_error($msg, E_USER_ERROR);
+       global $go_debug;
+
+       $bt = $go_debug>1 ? ('<hr>'.get_backtrace(true)) : '';
+       trigger_error($msg.$bt, E_USER_ERROR);
 }
 
 function display_notification($msg, $center=true)
@@ -55,7 +58,7 @@ function stock_item_heading($stock_id)
 {
        if ($stock_id != "") 
        {
-               $result = db_query("SELECT description, units FROM ".TB_PREF."stock_master WHERE stock_id='$stock_id'");                
+               $result = db_query("SELECT description, units FROM ".TB_PREF."stock_master WHERE stock_id=".db_escape($stock_id));
         $myrow = db_fetch_row($result);
         
        display_heading("$stock_id - $myrow[0]"); 
index 69810222a0ea2f6489c5748126404a5f08c2c5d4..c0e9e8c9a02646b3787c8eafc0906ea383baa576 100644 (file)
@@ -1306,42 +1306,47 @@ function _vl($mixed, $title = '', $exit = false)
 }
 
 function display_backtrace($cond=true, $msg='') {
-
        if ($cond) {
                if ($msg) 
                        $str = "<center><span class='headingtext'>$msg</span></center>\n";
                else
                        $str = '';
-               $str .= '<table border=0>';
-        $trace = debug_backtrace();
-               foreach($trace as $trn => $tr) {
-                       if (!$trn) continue;
-                       $str .= '<tr><td>';
-                       $str .= $tr['file'].':'.$tr['line'].': ';
-                       $str .= '</td><td>';
-                       if (isset($tr['type'])) {
-                               if($tr['type'] == '::') {
-                                       $str .= $tr['class'].'::';
-                               } else if($tr['type'] == '->') {
-                                       $str .= '('.$tr['class'].' Object)'.'->';
-                               }
-                       }
-                       foreach($tr['args'] as $n=>$a) {
-                               if (is_object($tr['args'][$n]))
-                                       $tr['args'][$n] = "(".get_class($tr['args'][$n])." Object)";
-                               if (is_array($tr['args'][$n]))
-                                       $tr['args'][$n] = "(Array[".count($tr['args'][$n])."])";
-                               else
-                                       $tr['args'][$n] = "'".$tr['args'][$n]."'";
+               $str .= get_backtrace(true);
+               display_error($str);
+       }
+}
+
+function get_backtrace($html = false)
+{
+       $str = '';
+       if ($html) $str .= '<table border=0>';
+       $trace = debug_backtrace();
+
+       foreach($trace as $trn => $tr) {
+               if (!$trn) continue;
+               if ($html) $str .= '<tr><td>';
+               $str .= $tr['file'].':'.$tr['line'].': ';
+               if ($html) $str .= '</td><td>';
+               if (isset($tr['type'])) {
+                       if($tr['type'] == '::') {
+                               $str .= $tr['class'].'::';
+                       } else if($tr['type'] == '->') {
+                               $str .= '('.$tr['class'].' Object)'.'->';
                        }
-                       $str .= $tr['function'].'('. implode(',',$tr['args']).')</td>';
+               }
 
-                       $str .= '</tr>';
+               foreach($tr['args'] as $n=>$a) {
+                       if (is_object($tr['args'][$n]))
+                               $tr['args'][$n] = "(".get_class($tr['args'][$n])." Object)";
+                       if (is_array($tr['args'][$n]))
+                               $tr['args'][$n] = "(Array[".count($tr['args'][$n])."])";
+                       else
+                               $tr['args'][$n] = "'".$tr['args'][$n]."'";
                }
-               
-               $str .= '</table>';
-               display_error($str);
+               $str .= $tr['function'].'('. implode(',',$tr['args']).')</td>';
        }
-}
 
+       if ($html) $str .= '</tr></table>';
+       return $str;
+}
 ?>
\ No newline at end of file