From 89cb648e9d031fa624e7814f89e90ccba2042124 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Sun, 3 May 2009 13:50:05 +0000 Subject: [PATCH] Fixed error handling in debug mode --- includes/db/connect_db.inc | 15 +++++++-------- includes/errors.inc | 20 ++++++++++++++------ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/includes/db/connect_db.inc b/includes/db/connect_db.inc index dc2dd027..fd6870e9 100644 --- a/includes/db/connect_db.inc +++ b/includes/db/connect_db.inc @@ -28,8 +28,6 @@ function db_query($sql, $err_msg=null) { global $db, $show_sql, $sql_trail, $select_trail, $go_debug; - if (!$err_msg && $go_debug) - $err_msg = "Debug mode error"; //echo "
$sql
"; if ($show_sql) { @@ -51,12 +49,13 @@ function db_query($sql, $err_msg=null) } } - if ($err_msg != null) - if (function_exists('xdebug_call_file')) - check_db_error('
At file '.xdebug_call_file().':'.xdebug_call_line().':
'.$err_msg, $sql); - else - check_db_error($err_msg, $sql); - + if ($err_msg != null || $go_debug) { + $exit = $err_msg != null; + if (function_exists('xdebug_call_file')) + check_db_error('
At file '.xdebug_call_file().':'.xdebug_call_line().':
'.$err_msg, $sql, $exit); + else + check_db_error($err_msg, $sql, $exit); + } return $result; } diff --git a/includes/errors.inc b/includes/errors.inc index 160d41e5..1a39f163 100644 --- a/includes/errors.inc +++ b/includes/errors.inc @@ -83,9 +83,15 @@ function error_box() { function display_db_error($msg, $sql_statement=null, $exit=true) { global $db, $debug; + + $warning = $msg==null; $db_error = db_error_no(); - $str = "" . _("DATABASE ERROR :") . " $msg
"; +// $str = "" . _("DATABASE ERROR :") . " $msg
"; + if($warning) + $str = "" . _("Debug mode database warning:") . "
"; + else + $str = "" . _("DATABASE ERROR :") . " $msg
"; if ($db_error != 0) { @@ -99,9 +105,10 @@ function display_db_error($msg, $sql_statement=null, $exit=true) } $str .= "

"; - - trigger_error($str, E_USER_ERROR); - + if($msg) + trigger_error($str, E_USER_ERROR); + else // $msg can be null here only in debug mode, otherwise the error is ignored + trigger_error($str, E_USER_WARNING); if ($exit) exit; } @@ -127,8 +134,9 @@ function check_db_error($msg, $sql_statement, $exit_if_error=true, $rollback_if_ if ($db_error != 0) { - if (!frindly_db_error($db_error)) - display_db_error($msg, $sql_statement, false); + if (!frindly_db_error($db_error)) { + display_db_error($msg, $sql_statement, false); + } if ($rollback_if_error) { -- 2.30.2