Pull back for now on switch of PEAR error mode to exceptions; seems to trigger out exceptions at various times we don't want them.
For instance this was throwing an exception for DB_DataObject::staticGet when there's no match... definitely not what we want when all our code expects to get a nice null. Example of this causing trouble: http://gitorious.org/statusnet/mainline/merge_requests/131 Revert "Don't attempt to retrieve the current user from the DB while processing a DB error" This reverts commit68347691b0
. Revert "Use PHP exceptions for PEAR error handling." This reverts commitd8212977ce
.
This commit is contained in:
parent
b994d529f4
commit
f62b8a80cf
29
index.php
29
index.php
@ -37,6 +37,8 @@ define('INSTALLDIR', dirname(__FILE__));
|
|||||||
define('STATUSNET', true);
|
define('STATUSNET', true);
|
||||||
define('LACONICA', true); // compatibility
|
define('LACONICA', true); // compatibility
|
||||||
|
|
||||||
|
require_once INSTALLDIR . '/lib/common.php';
|
||||||
|
|
||||||
$user = null;
|
$user = null;
|
||||||
$action = null;
|
$action = null;
|
||||||
|
|
||||||
@ -66,15 +68,13 @@ function getPath($req)
|
|||||||
*/
|
*/
|
||||||
function handleError($error)
|
function handleError($error)
|
||||||
{
|
{
|
||||||
try {
|
|
||||||
|
|
||||||
if ($error->getCode() == DB_DATAOBJECT_ERROR_NODATA) {
|
if ($error->getCode() == DB_DATAOBJECT_ERROR_NODATA) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$logmsg = "PEAR error: " . $error->getMessage();
|
$logmsg = "PEAR error: " . $error->getMessage();
|
||||||
if ($error instanceof PEAR_Exception && common_config('site', 'logdebug')) {
|
if (common_config('site', 'logdebug')) {
|
||||||
$logmsg .= " : ". $error->toText();
|
$logmsg .= " : ". $error->getDebugInfo();
|
||||||
}
|
}
|
||||||
// DB queries often end up with a lot of newlines; merge to a single line
|
// DB queries often end up with a lot of newlines; merge to a single line
|
||||||
// for easier grepability...
|
// for easier grepability...
|
||||||
@ -83,21 +83,14 @@ function handleError($error)
|
|||||||
|
|
||||||
// @fixme backtrace output should be consistent with exception handling
|
// @fixme backtrace output should be consistent with exception handling
|
||||||
if (common_config('site', 'logdebug')) {
|
if (common_config('site', 'logdebug')) {
|
||||||
$bt = $error->getTrace();
|
$bt = $error->getBacktrace();
|
||||||
foreach ($bt as $n => $line) {
|
foreach ($bt as $n => $line) {
|
||||||
common_log(LOG_ERR, formatBacktraceLine($n, $line));
|
common_log(LOG_ERR, formatBacktraceLine($n, $line));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($error instanceof DB_DataObject_Error
|
if ($error instanceof DB_DataObject_Error
|
||||||
|| $error instanceof DB_Error
|
|| $error instanceof DB_Error
|
||||||
|| ($error instanceof PEAR_Exception && $error->getCode() == -24)
|
|
||||||
) {
|
) {
|
||||||
//If we run into a DB error, assume we can't connect to the DB at all
|
|
||||||
//so set the current user to null, so we don't try to access the DB
|
|
||||||
//while rendering the error page.
|
|
||||||
global $_cur;
|
|
||||||
$_cur = null;
|
|
||||||
|
|
||||||
$msg = sprintf(
|
$msg = sprintf(
|
||||||
_(
|
_(
|
||||||
'The database for %s isn\'t responding correctly, '.
|
'The database for %s isn\'t responding correctly, '.
|
||||||
@ -118,17 +111,9 @@ function handleError($error)
|
|||||||
|
|
||||||
$dac = new DBErrorAction($msg, 500);
|
$dac = new DBErrorAction($msg, 500);
|
||||||
$dac->showPage();
|
$dac->showPage();
|
||||||
|
|
||||||
} catch (Exception $e) {
|
|
||||||
echo _('An error occurred.');
|
|
||||||
}
|
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
set_exception_handler('handleError');
|
|
||||||
|
|
||||||
require_once INSTALLDIR . '/lib/common.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format a backtrace line for debug output roughly like debug_print_backtrace() does.
|
* Format a backtrace line for debug output roughly like debug_print_backtrace() does.
|
||||||
* Exceptions already have this built in, but PEAR error objects just give us the array.
|
* Exceptions already have this built in, but PEAR error objects just give us the array.
|
||||||
@ -253,6 +238,10 @@ function main()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For database errors
|
||||||
|
|
||||||
|
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handleError');
|
||||||
|
|
||||||
// Make sure RW database is setup
|
// Make sure RW database is setup
|
||||||
|
|
||||||
setupRW();
|
setupRW();
|
||||||
|
@ -71,7 +71,6 @@ if (!function_exists('dl')) {
|
|||||||
# global configuration object
|
# global configuration object
|
||||||
|
|
||||||
require_once('PEAR.php');
|
require_once('PEAR.php');
|
||||||
require_once('PEAR/Exception.php');
|
|
||||||
require_once('DB/DataObject.php');
|
require_once('DB/DataObject.php');
|
||||||
require_once('DB/DataObject/Cast.php'); # for dates
|
require_once('DB/DataObject/Cast.php'); # for dates
|
||||||
|
|
||||||
@ -129,17 +128,6 @@ require_once INSTALLDIR.'/lib/activity.php';
|
|||||||
require_once INSTALLDIR.'/lib/clientexception.php';
|
require_once INSTALLDIR.'/lib/clientexception.php';
|
||||||
require_once INSTALLDIR.'/lib/serverexception.php';
|
require_once INSTALLDIR.'/lib/serverexception.php';
|
||||||
|
|
||||||
|
|
||||||
//set PEAR error handling to use regular PHP exceptions
|
|
||||||
function PEAR_ErrorToPEAR_Exception($err)
|
|
||||||
{
|
|
||||||
if ($err->getCode()) {
|
|
||||||
throw new PEAR_Exception($err->getMessage(), $err->getCode());
|
|
||||||
}
|
|
||||||
throw new PEAR_Exception($err->getMessage());
|
|
||||||
}
|
|
||||||
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'PEAR_ErrorToPEAR_Exception');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
StatusNet::init(@$server, @$path, @$conffile);
|
StatusNet::init(@$server, @$path, @$conffile);
|
||||||
} catch (NoConfigException $e) {
|
} catch (NoConfigException $e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user