mirror of
https://github.com/php/php-src.git
synced 2024-11-24 18:34:21 +08:00
PEAR:
* added $debuginfo parameter to PEAR_Error constructor * put last query in $debuginfo from DB_common::raiseError() @PEAR: add last executed query as debug info in DB errors (Stig)
This commit is contained in:
parent
63aec84825
commit
7c53e635b2
22
pear/DB.php
22
pear/DB.php
@ -469,17 +469,21 @@ class DB_Error extends PEAR_Error {
|
||||
*
|
||||
* @param $code mixed DB error code, or string with error message.
|
||||
* @param $mode int what "error mode" to operate in
|
||||
* @param $level what error level to use for $mode == PEAR_ERROR_TRIGGER
|
||||
* @param $level what error level to use for $mode & PEAR_ERROR_TRIGGER
|
||||
* @param $debuginfo additional debug info, such as the last query
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @see PEAR_Error
|
||||
*/
|
||||
function DB_Error($code = DB_ERROR,
|
||||
$mode = PEAR_ERROR_RETURN,
|
||||
$level = E_USER_NOTICE) {
|
||||
$level = E_USER_NOTICE,
|
||||
$debuginfo = null) {
|
||||
if (is_int($code)) {
|
||||
$this->PEAR_Error("DB Error: " . DB::errorMessage($code), $code, $mode, $level);
|
||||
$this->PEAR_Error("DB Error: " . DB::errorMessage($code), $code, $mode, $level, $debuginfo);
|
||||
} else {
|
||||
$this->PEAR_Error("DB Error: $code", 0, $mode, $level);
|
||||
$this->PEAR_Error("DB Error: $code", 0, $mode, $level, $debuginfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -497,16 +501,20 @@ class DB_Warning extends PEAR_Error {
|
||||
* @param $code mixed DB error code, or string with error message.
|
||||
* @param $mode int what "error mode" to operate in
|
||||
* @param $level what error level to use for $mode == PEAR_ERROR_TRIGGER
|
||||
* @param $debuginfo additional debug info, such as the last query
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @see PEAR_Error
|
||||
*/
|
||||
function DB_Warning($code = DB_WARNING,
|
||||
$mode = PEAR_ERROR_RETURN,
|
||||
$level = E_USER_NOTICE) {
|
||||
$level = E_USER_NOTICE,
|
||||
$debuginfo = null) {
|
||||
if (is_int($code)) {
|
||||
$this->PEAR_Error("DB Warning: " . DB::errorMessage($code), $code, $mode, $level);
|
||||
$this->PEAR_Error("DB Warning: " . DB::errorMessage($code), $code, $mode, $level, $debuginfo);
|
||||
} else {
|
||||
$this->PEAR_Error("DB Warning: $code", 0, $mode, $level);
|
||||
$this->PEAR_Error("DB Warning: $code", 0, $mode, $level, $debuginfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -144,12 +144,11 @@ class PEAR_Error
|
||||
var $error_message_prefix = '';
|
||||
var $error_prepend = '';
|
||||
var $error_append = '';
|
||||
|
||||
var $mode = PEAR_ERROR_RETURN;
|
||||
var $level = E_USER_NOTICE;
|
||||
var $code = -1;
|
||||
|
||||
var $message = '';
|
||||
var $debuginfo = '';
|
||||
|
||||
// Wait until we have a stack-groping function in PHP.
|
||||
//var $file = '';
|
||||
@ -178,14 +177,16 @@ class PEAR_Error
|
||||
function PEAR_Error($message = 'unknown error',
|
||||
$code = 0,
|
||||
$mode = null,
|
||||
$options = null)
|
||||
$options = null,
|
||||
$debuginfo = null)
|
||||
{
|
||||
if ($mode === null) {
|
||||
$mode = PEAR_ERROR_RETURN;
|
||||
}
|
||||
$this->message = $message;
|
||||
$this->code = $code;
|
||||
$this->mode = $mode;
|
||||
$this->message = $message;
|
||||
$this->code = $code;
|
||||
$this->mode = $mode;
|
||||
$this->debuginfo = $debuginfo;
|
||||
if ($mode & PEAR_ERROR_CALLBACK) {
|
||||
$this->level = E_USER_NOTICE;
|
||||
$this->callback = $options;
|
||||
@ -275,6 +276,19 @@ class PEAR_Error
|
||||
return get_class($this);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getDebugInfo()
|
||||
|
||||
/**
|
||||
* Get additional debug information supplied by the application.
|
||||
*
|
||||
* @return string debug information
|
||||
*/
|
||||
function getDebugInfo ()
|
||||
{
|
||||
return $this->debuginfo;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ toString()
|
||||
|
||||
@ -296,10 +310,12 @@ class PEAR_Error
|
||||
$callback = $this->callback;
|
||||
}
|
||||
return sprintf('[%s: message="%s" code=%d mode=callback '.
|
||||
'callback=%s prefix="%s" prepend="%s" append="%s"]',
|
||||
'callback=%s prefix="%s" prepend="%s" append="%s" '.
|
||||
'debug="%s"]',
|
||||
get_class($this), $this->message, $this->code,
|
||||
$callback, $this->error_message_prefix,
|
||||
$this->error_prepend, $this->error_append);
|
||||
$this->error_prepend, $this->error_append,
|
||||
$this->debuginfo);
|
||||
}
|
||||
if ($this->mode & PEAR_ERROR_CALLBACK) {
|
||||
$modes[] = "callback";
|
||||
@ -316,11 +332,13 @@ class PEAR_Error
|
||||
if ($this->mode & PEAR_ERROR_RETURN) {
|
||||
$modes[] = "return";
|
||||
}
|
||||
return sprintf('[%s: message="%s" code=%d mode=%s level=%s prefix="%s" prepend="%s" append="%s"]',
|
||||
return sprintf('[%s: message="%s" code=%d mode=%s level=%s prefix="%s" '.
|
||||
'prepend="%s" append="%s" debug="%s"]',
|
||||
get_class($this), $this->message, $this->code,
|
||||
implode("|", $modes), $levels[$this->level],
|
||||
$this->error_message_prefix,
|
||||
$this->error_prepend, $this->error_append);
|
||||
$this->error_prepend, $this->error_append,
|
||||
$this->debuginfo);
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
@ -79,26 +79,26 @@ print $err->toString() . "\n";
|
||||
--GET--
|
||||
--POST--
|
||||
--EXPECT--
|
||||
default PEAR_Error: [pear_error: message="unknown error" code=0 mode=return level=notice prefix="" prepend="" append=""]
|
||||
default PEAR_Error: [pear_error: message="unknown error" code=0 mode=return level=notice prefix="" prepend="" append="" debug=""]
|
||||
Testing it: bool(true)
|
||||
This is not an error: bool(false)
|
||||
Now trying a bunch of variations...
|
||||
different message: [pear_error: message="test error" code=0 mode=return level=notice prefix="" prepend="" append=""]
|
||||
different message,code: [pear_error: message="test error" code=-42 mode=return level=notice prefix="" prepend="" append=""]
|
||||
mode=print: test error[pear_error: message="test error" code=-42 mode=print level=notice prefix="" prepend="" append=""]
|
||||
mode=callback(function): errorhandler function called, obj=[pear_error: message="test error" code=-42 mode=callback callback=errorhandler prefix="" prepend="" append=""]
|
||||
mode=callback(method): errorhandler method called, obj=[pear_error: message="test error" code=-42 mode=callback callback=errorclass::errorhandler prefix="" prepend="" append=""]
|
||||
different message: [pear_error: message="test error" code=0 mode=return level=notice prefix="" prepend="" append="" debug=""]
|
||||
different message,code: [pear_error: message="test error" code=-42 mode=return level=notice prefix="" prepend="" append="" debug=""]
|
||||
mode=print: test error[pear_error: message="test error" code=-42 mode=print level=notice prefix="" prepend="" append="" debug=""]
|
||||
mode=callback(function): errorhandler function called, obj=[pear_error: message="test error" code=-42 mode=callback callback=errorhandler prefix="" prepend="" append="" debug=""]
|
||||
mode=callback(method): errorhandler method called, obj=[pear_error: message="test error" code=-42 mode=callback callback=errorclass::errorhandler prefix="" prepend="" append="" debug=""]
|
||||
mode=print&trigger: test error<br>
|
||||
<b>Notice</b>: test error in <b>PEAR.php</b> on line <b>203</b><br>
|
||||
[pear_error: message="test error" code=-42 mode=print|trigger level=notice prefix="" prepend="" append=""]
|
||||
<b>Notice</b>: test error in <b>PEAR.php</b> on line <b>204</b><br>
|
||||
[pear_error: message="test error" code=-42 mode=print|trigger level=notice prefix="" prepend="" append="" debug=""]
|
||||
mode=trigger: <br>
|
||||
<b>Notice</b>: test error in <b>PEAR.php</b> on line <b>203</b><br>
|
||||
[pear_error: message="test error" code=-42 mode=trigger level=notice prefix="" prepend="" append=""]
|
||||
<b>Notice</b>: test error in <b>PEAR.php</b> on line <b>204</b><br>
|
||||
[pear_error: message="test error" code=-42 mode=trigger level=notice prefix="" prepend="" append="" debug=""]
|
||||
mode=trigger,level=notice: <br>
|
||||
<b>Notice</b>: test error in <b>PEAR.php</b> on line <b>203</b><br>
|
||||
[pear_error: message="test error" code=-42 mode=trigger level=notice prefix="" prepend="" append=""]
|
||||
<b>Notice</b>: test error in <b>PEAR.php</b> on line <b>204</b><br>
|
||||
[pear_error: message="test error" code=-42 mode=trigger level=notice prefix="" prepend="" append="" debug=""]
|
||||
mode=trigger,level=warning: <br>
|
||||
<b>Warning</b>: test error in <b>PEAR.php</b> on line <b>203</b><br>
|
||||
[pear_error: message="test error" code=-42 mode=trigger level=warning prefix="" prepend="" append=""]
|
||||
<b>Warning</b>: test error in <b>PEAR.php</b> on line <b>204</b><br>
|
||||
[pear_error: message="test error" code=-42 mode=trigger level=warning prefix="" prepend="" append="" debug=""]
|
||||
mode=trigger,level=error: <br>
|
||||
<b>Fatal error</b>: test error in <b>PEAR.php</b> on line <b>203</b><br>
|
||||
<b>Fatal error</b>: test error in <b>PEAR.php</b> on line <b>204</b><br>
|
||||
|
Loading…
Reference in New Issue
Block a user