X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FError.php;h=e6b543fac9b7b6426449ade8972164310bb51cbf;hb=5667521530926d61b370a4bb0806b7e5ad63ccbc;hp=609506f88a83c74ceff6dd20b0c453c3ad3c8e25;hpb=4eeab98aa76b95b35bc71c9895d2d9245a4009c6;p=civicrm-core.git diff --git a/CRM/Core/Error.php b/CRM/Core/Error.php index 609506f88a..e6b543fac9 100644 --- a/CRM/Core/Error.php +++ b/CRM/Core/Error.php @@ -2,7 +2,7 @@ /* +--------------------------------------------------------------------+ - | CiviCRM version 4.5 | + | CiviCRM version 4.6 | +--------------------------------------------------------------------+ | Copyright CiviCRM LLC (c) 2004-2014 | +--------------------------------------------------------------------+ @@ -61,9 +61,6 @@ class CRM_Exception extends PEAR_Exception { * @param string exception message * @param int $code * @param Exception $previous - * - * @internal param array|\Exception|int|null|\PEAR_Error $exception cause - * @internal param int|null $exception code or null */ public function __construct($message = NULL, $code = 0, Exception$previous = NULL) { parent::__construct($message, $code, $previous); @@ -76,13 +73,13 @@ class CRM_Exception extends PEAR_Exception { class CRM_Core_Error extends PEAR_ErrorStack { /** - * status code of various types of errors + * Status code of various types of errors * @var const */ - CONST FATAL_ERROR = 2; - CONST DUPLICATE_CONTACT = 8001; - CONST DUPLICATE_CONTRIBUTION = 8002; - CONST DUPLICATE_PARTICIPANT = 8003; + const FATAL_ERROR = 2; + const DUPLICATE_CONTACT = 8001; + const DUPLICATE_CONTRIBUTION = 8002; + const DUPLICATE_PARTICIPANT = 8003; /** * We only need one instance of this object. So we use the singleton @@ -106,7 +103,7 @@ class CRM_Core_Error extends PEAR_ErrorStack { public static $modeException = NULL; /** - * singleton function used to manage this object. + * Singleton function used to manage this object. * * @param null $package * @param bool $msgCallback @@ -117,7 +114,7 @@ class CRM_Core_Error extends PEAR_ErrorStack { * @return object * @static */ - static function &singleton($package = NULL, $msgCallback = FALSE, $contextCallback = FALSE, $throwPEAR_Error = FALSE, $stackClass = 'PEAR_ErrorStack') { + public static function &singleton($package = NULL, $msgCallback = FALSE, $contextCallback = FALSE, $throwPEAR_Error = FALSE, $stackClass = 'PEAR_ErrorStack') { if (self::$_singleton === NULL) { self::$_singleton = new CRM_Core_Error('CiviCRM'); } @@ -125,9 +122,9 @@ class CRM_Core_Error extends PEAR_ErrorStack { } /** - * constructor + * Constructor */ - function __construct() { + public function __construct() { parent::__construct('CiviCRM'); $log = CRM_Core_Config::getLog(); @@ -161,7 +158,7 @@ class CRM_Core_Error extends PEAR_ErrorStack { * @param $error * @param string $separator */ - static function displaySessionError(&$error, $separator = '
') { + public static function displaySessionError(&$error, $separator = '
') { $message = self::getMessages($error, $separator); if ($message) { $status = ts("Payment Processor Error message") . "{$separator} $message"; @@ -171,7 +168,7 @@ class CRM_Core_Error extends PEAR_ErrorStack { } /** - * create the main callback method. this method centralizes error processing. + * Create the main callback method. this method centralizes error processing. * * the errors we expect are from the pear modules DB, DB_DataObject * which currently use PEAR::raiseError to notify of error messages. @@ -179,7 +176,6 @@ class CRM_Core_Error extends PEAR_ErrorStack { * @param object PEAR_Error * * @return void - * @access public */ public static function handle($pearError) { @@ -301,22 +297,18 @@ class CRM_Core_Error extends PEAR_ErrorStack { } /** - * display an error page with an error message describing what happened + * Display an error page with an error message describing what happened * - * @param null $message - * @param null $code - * @param null $email + * @param string $message the error message + * @param string $code the error code if any + * @param string $email the email address to notify of this situation * * @throws Exception - * @internal param \message $string the error message - * @internal param \code $string the error code if any - * @internal param \email $string the email address to notify of this situation * * @return void * @static - * @acess public */ - static function fatal($message = NULL, $code = NULL, $email = NULL) { + public static function fatal($message = NULL, $code = NULL, $email = NULL) { $vars = array( 'message' => $message, 'code' => $code, @@ -361,6 +353,13 @@ class CRM_Core_Error extends PEAR_ErrorStack { } } + if ($config->backtrace) { + self::backtrace(); + } + + CRM_Core_Error::debug_var('Fatal Error Details', $vars); + CRM_Core_Error::backtrace('backTrace', TRUE); + // If we are in an ajax callback, format output appropriately if (CRM_Utils_Array::value('snippet', $_REQUEST) === CRM_Core_Smarty::PRINT_JSON) { $out = array( @@ -376,22 +375,16 @@ class CRM_Core_Error extends PEAR_ErrorStack { CRM_Core_Page_AJAX::returnJsonResponse($out); } - if ($config->backtrace) { - self::backtrace(); - } - $template = CRM_Core_Smarty::singleton(); $template->assign($vars); - CRM_Core_Error::debug_var('Fatal Error Details', $vars); - CRM_Core_Error::backtrace('backTrace', TRUE); $config->userSystem->outputError($template->fetch($config->fatalErrorTemplate)); self::abend(CRM_Core_Error::FATAL_ERROR); } /** - * display an error page with an error message describing what happened + * Display an error page with an error message describing what happened * * This function is evil -- it largely replicates fatal(). Hopefully the * entire CRM_Core_Error system can be hollowed out and replaced with @@ -401,9 +394,14 @@ class CRM_Core_Error extends PEAR_ErrorStack { * * @return void * @static - * @acess public */ - static function handleUnhandledException($exception) { + public static function handleUnhandledException($exception) { + try { + CRM_Utils_Hook::unhandledException($exception); + } catch (Exception $other) { + // if the exception-handler generates an exception, then that sucks! oh, well. carry on. + CRM_Core_Error::debug_var('handleUnhandledException_nestedException', self::formatTextException($other)); + } $config = CRM_Core_Config::singleton(); $vars = array( 'message' => $exception->getMessage(), @@ -464,7 +462,7 @@ class CRM_Core_Error extends PEAR_ErrorStack { } /** - * outputs pre-formatted debug information. Flushes the buffers + * Outputs pre-formatted debug information. Flushes the buffers * so we can interrupt a potential POST/redirect * * @param string name of debug section @@ -476,10 +474,9 @@ class CRM_Core_Error extends PEAR_ErrorStack { * subsystem is not initialized - CRM-13765 * * @return string the generated output - * @access public * @static */ - static function debug($name, $variable = NULL, $log = TRUE, $html = TRUE, $checkPermission = TRUE) { + public static function debug($name, $variable = NULL, $log = TRUE, $html = TRUE, $checkPermission = TRUE) { $error = self::singleton(); if ($variable === NULL) { @@ -516,19 +513,14 @@ class CRM_Core_Error extends PEAR_ErrorStack { * Similar to the function debug. Only difference is * in the formatting of the output. * - * @param $variable_name - * @param $variable - * @param bool $print - * @param bool $log + * @param string $variable_name + * @param mixed $variable + * @param bool $print should we use print_r ? (else we use var_dump) + * @param bool $log should we log or return the output * @param string $comp variable name * - * @internal param \reference $mixed to variables that we need a trace of - * @internal param \should $bool we use print_r ? (else we use var_dump) - * @internal param \should $bool we log or return the output - * * @return string the generated output * - * @access public * * @static * @@ -567,7 +559,7 @@ class CRM_Core_Error extends PEAR_ErrorStack { } /** - * display the error message on terminal + * Display the error message on terminal * * @param $message * @param bool $out should we log or return the output @@ -575,11 +567,10 @@ class CRM_Core_Error extends PEAR_ErrorStack { * @param string $comp message to be output * @return string format of the backtrace * - * @access public * * @static */ - static function debug_log_message($message, $out = FALSE, $comp = '') { + public static function debug_log_message($message, $out = FALSE, $comp = '') { $config = CRM_Core_Config::singleton(); $file_log = self::createDebugLogger($comp); @@ -603,7 +594,7 @@ class CRM_Core_Error extends PEAR_ErrorStack { /** * Append to the query log (if enabled) */ - static function debug_query($string) { + public static function debug_query($string) { if ( defined( 'CIVICRM_DEBUG_LOG_QUERY' ) ) { if ( CIVICRM_DEBUG_LOG_QUERY == 'backtrace' ) { CRM_Core_Error::backtrace( $string, true ); @@ -618,7 +609,7 @@ class CRM_Core_Error extends PEAR_ErrorStack { * * @param string $query */ - static function debug_query_result($query) { + public static function debug_query_result($query) { $dao = CRM_Core_DAO::executeQuery($query); $results = array(); while ($dao->fetch()) { @@ -634,7 +625,7 @@ class CRM_Core_Error extends PEAR_ErrorStack { * * @return Log */ - static function createDebugLogger($comp = '') { + public static function createDebugLogger($comp = '') { $config = CRM_Core_Config::singleton(); if ($comp) { @@ -666,7 +657,7 @@ class CRM_Core_Error extends PEAR_ErrorStack { * @param string $msg * @param bool $log */ - static function backtrace($msg = 'backTrace', $log = FALSE) { + public static function backtrace($msg = 'backTrace', $log = FALSE) { $backTrace = debug_backtrace(); $message = self::formatBacktrace($backTrace); if (!$log) { @@ -685,7 +676,7 @@ class CRM_Core_Error extends PEAR_ErrorStack { * @param int $maxArgLen maximum number of characters to show from each argument string * @return string printable plain-text */ - static function formatBacktrace($backTrace, $showArgs = TRUE, $maxArgLen = 80) { + public static function formatBacktrace($backTrace, $showArgs = TRUE, $maxArgLen = 80) { $message = ''; foreach (self::parseBacktrace($backTrace, $showArgs, $maxArgLen) as $idx => $trace) { $message .= sprintf("#%s %s\n", $idx, $trace); @@ -704,7 +695,7 @@ class CRM_Core_Error extends PEAR_ErrorStack { * @see debug_backtrace * @see Exception::getTrace() */ - static function parseBacktrace($backTrace, $showArgs = TRUE, $maxArgLen = 80) { + public static function parseBacktrace($backTrace, $showArgs = TRUE, $maxArgLen = 80) { $ret = array(); foreach ($backTrace as $trace) { $args = array(); @@ -768,7 +759,7 @@ class CRM_Core_Error extends PEAR_ErrorStack { * @param Exception $e * @return string printable HTML text */ - static function formatHtmlException(Exception $e) { + public static function formatHtmlException(Exception $e) { $msg = ''; // Exception metadata @@ -802,7 +793,7 @@ class CRM_Core_Error extends PEAR_ErrorStack { * @param Exception $e * @return string printable plain text */ - static function formatTextException(Exception $e) { + public static function formatTextException(Exception $e) { $msg = get_class($e) . ": \"" . $e->getMessage() . "\"\n"; $ei = $e; @@ -822,11 +813,11 @@ class CRM_Core_Error extends PEAR_ErrorStack { * @param $message * @param int $code * @param string $level - * @param null $params + * @param array $params * * @return object */ - static function createError($message, $code = 8000, $level = 'Fatal', $params = NULL) { + public static function createError($message, $code = 8000, $level = 'Fatal', $params = NULL) { $error = CRM_Core_Error::singleton(); $error->push($code, $level, array($params), $message); return $error; @@ -840,7 +831,6 @@ class CRM_Core_Error extends PEAR_ErrorStack { * @param null $redirect * @param string $title * @return void - * @access public * @static */ public static function statusBounce($status, $redirect = NULL, $title = NULL) { @@ -859,9 +849,8 @@ class CRM_Core_Error extends PEAR_ErrorStack { } /** - * Function to reset the error stack + * Reset the error stack * - * @access public * @static */ public static function reset() { @@ -886,7 +875,6 @@ class CRM_Core_Error extends PEAR_ErrorStack { * * @param object $obj The PEAR_ERROR object * @return object $obj - * @access public * @static */ public static function nullHandler($obj) {