summaryrefslogtreecommitdiff
path: root/index.php
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-03-16 16:23:19 -0700
committerBrion Vibber <brion@pobox.com>2010-03-16 16:32:25 -0700
commitf62b8a80cf33ac8529d0736c51dc060a9d235369 (patch)
tree5891540dd17a29fb37ef764d9cf48d697a3612c6 /index.php
parentb994d529f4de53df6350e12b5e81889cee17f317 (diff)
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 commit 68347691b0c7fb3f81415abd7fcdc5aec85cc554. Revert "Use PHP exceptions for PEAR error handling." This reverts commit d8212977ce7f911d4f9bd6e55f94aea059a86782.
Diffstat (limited to 'index.php')
-rw-r--r--index.php103
1 files changed, 46 insertions, 57 deletions
diff --git a/index.php b/index.php
index 65f251bcc..36ba3a0d2 100644
--- a/index.php
+++ b/index.php
@@ -37,6 +37,8 @@ define('INSTALLDIR', dirname(__FILE__));
define('STATUSNET', true);
define('LACONICA', true); // compatibility
+require_once INSTALLDIR . '/lib/common.php';
+
$user = null;
$action = null;
@@ -66,69 +68,52 @@ function getPath($req)
*/
function handleError($error)
{
- try {
-
- if ($error->getCode() == DB_DATAOBJECT_ERROR_NODATA) {
- return;
- }
+ if ($error->getCode() == DB_DATAOBJECT_ERROR_NODATA) {
+ return;
+ }
- $logmsg = "PEAR error: " . $error->getMessage();
- if ($error instanceof PEAR_Exception && common_config('site', 'logdebug')) {
- $logmsg .= " : ". $error->toText();
- }
- // DB queries often end up with a lot of newlines; merge to a single line
- // for easier grepability...
- $logmsg = str_replace("\n", " ", $logmsg);
- common_log(LOG_ERR, $logmsg);
-
- // @fixme backtrace output should be consistent with exception handling
- if (common_config('site', 'logdebug')) {
- $bt = $error->getTrace();
- foreach ($bt as $n => $line) {
- common_log(LOG_ERR, formatBacktraceLine($n, $line));
- }
- }
- if ($error instanceof DB_DataObject_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(
- _(
- 'The database for %s isn\'t responding correctly, '.
- 'so the site won\'t work properly. '.
- 'The site admins probably know about the problem, '.
- 'but you can contact them at %s to make sure. '.
- 'Otherwise, wait a few minutes and try again.'
- ),
- common_config('site', 'name'),
- common_config('site', 'email')
- );
- } else {
- $msg = _(
- 'An important error occured, probably related to email setup. '.
- 'Check logfiles for more info..'
- );
+ $logmsg = "PEAR error: " . $error->getMessage();
+ if (common_config('site', 'logdebug')) {
+ $logmsg .= " : ". $error->getDebugInfo();
+ }
+ // DB queries often end up with a lot of newlines; merge to a single line
+ // for easier grepability...
+ $logmsg = str_replace("\n", " ", $logmsg);
+ common_log(LOG_ERR, $logmsg);
+
+ // @fixme backtrace output should be consistent with exception handling
+ if (common_config('site', 'logdebug')) {
+ $bt = $error->getBacktrace();
+ foreach ($bt as $n => $line) {
+ common_log(LOG_ERR, formatBacktraceLine($n, $line));
}
-
- $dac = new DBErrorAction($msg, 500);
- $dac->showPage();
-
- } catch (Exception $e) {
- echo _('An error occurred.');
}
+ if ($error instanceof DB_DataObject_Error
+ || $error instanceof DB_Error
+ ) {
+ $msg = sprintf(
+ _(
+ 'The database for %s isn\'t responding correctly, '.
+ 'so the site won\'t work properly. '.
+ 'The site admins probably know about the problem, '.
+ 'but you can contact them at %s to make sure. '.
+ 'Otherwise, wait a few minutes and try again.'
+ ),
+ common_config('site', 'name'),
+ common_config('site', 'email')
+ );
+ } else {
+ $msg = _(
+ 'An important error occured, probably related to email setup. '.
+ 'Check logfiles for more info..'
+ );
+ }
+
+ $dac = new DBErrorAction($msg, 500);
+ $dac->showPage();
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.
* Exceptions already have this built in, but PEAR error objects just give us the array.
@@ -253,6 +238,10 @@ function main()
return;
}
+ // For database errors
+
+ PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handleError');
+
// Make sure RW database is setup
setupRW();