3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Start of the Error framework. We should check out and inherit from
30 * PEAR_ErrorStack and use that framework
33 * @copyright CiviCRM LLC (c) 2004-2017
36 require_once 'PEAR/ErrorStack.php';
37 require_once 'PEAR/Exception.php';
38 require_once 'CRM/Core/Exception.php';
40 require_once 'Log.php';
45 class CRM_Exception
extends PEAR_Exception
{
47 * Redefine the exception so message isn't optional.
49 * Supported signatures:
50 * - PEAR_Exception(string $message);
51 * - PEAR_Exception(string $message, int $code);
52 * - PEAR_Exception(string $message, Exception $cause);
53 * - PEAR_Exception(string $message, Exception $cause, int $code);
54 * - PEAR_Exception(string $message, PEAR_Error $cause);
55 * - PEAR_Exception(string $message, PEAR_Error $cause, int $code);
56 * - PEAR_Exception(string $message, array $causes);
57 * - PEAR_Exception(string $message, array $causes, int $code);
59 * @param string $message exception message
61 * @param Exception $previous
63 public function __construct($message = NULL, $code = 0, Exception
$previous = NULL) {
64 parent
::__construct($message, $code, $previous);
70 * Class CRM_Core_Error
72 class CRM_Core_Error
extends PEAR_ErrorStack
{
75 * Status code of various types of errors.
77 const FATAL_ERROR
= 2;
78 const DUPLICATE_CONTACT
= 8001;
79 const DUPLICATE_CONTRIBUTION
= 8002;
80 const DUPLICATE_PARTICIPANT
= 8003;
83 * We only need one instance of this object. So we use the singleton
84 * pattern and cache the instance in this variable
87 private static $_singleton = NULL;
90 * The logger object for this application.
93 private static $_log = NULL;
96 * If modeException == true, errors are raised as exception instead of returning civicrm_errors
98 public static $modeException = NULL;
101 * Singleton function used to manage this object.
103 * @param null $package
104 * @param bool $msgCallback
105 * @param bool $contextCallback
106 * @param bool $throwPEAR_Error
107 * @param string $stackClass
111 public static function &singleton($package = NULL, $msgCallback = FALSE, $contextCallback = FALSE, $throwPEAR_Error = FALSE, $stackClass = 'PEAR_ErrorStack') {
112 if (self
::$_singleton === NULL) {
113 self
::$_singleton = new CRM_Core_Error('CiviCRM');
115 return self
::$_singleton;
121 public function __construct() {
122 parent
::__construct('CiviCRM');
124 $log = CRM_Core_Config
::getLog();
125 $this->setLogger($log);
127 // PEAR<=1.9.0 does not declare "static" properly.
128 if (!is_callable(array('PEAR', '__callStatic'))) {
129 $this->setDefaultCallback(array($this, 'handlePES'));
132 PEAR_ErrorStack
::setDefaultCallback(array($this, 'handlePES'));
138 * @param string $separator
140 * @return array|null|string
142 static public function getMessages(&$error, $separator = '<br />') {
143 if (is_a($error, 'CRM_Core_Error')) {
144 $errors = $error->getErrors();
146 foreach ($errors as $e) {
147 $message[] = $e['code'] . ': ' . $e['message'];
149 $message = implode($separator, $message);
156 * Status display function specific to payment processor errors.
158 * @param string $separator
160 public static function displaySessionError(&$error, $separator = '<br />') {
161 $message = self
::getMessages($error, $separator);
163 $status = ts("Payment Processor Error message") . "{$separator} $message";
164 $session = CRM_Core_Session
::singleton();
165 $session->setStatus($status);
170 * Create the main callback method. this method centralizes error processing.
172 * the errors we expect are from the pear modules DB, DB_DataObject
173 * which currently use PEAR::raiseError to notify of error messages.
175 * @param object $pearError PEAR_Error
177 public static function handle($pearError) {
178 if (defined('CIVICRM_TEST')) {
179 return self
::simpleHandler($pearError);
182 // setup smarty with config, session and template location.
183 $template = CRM_Core_Smarty
::singleton();
184 $config = CRM_Core_Config
::singleton();
186 if ($config->backtrace
) {
190 // create the error array
191 $error = self
::getErrorDetails($pearError);
193 // We access connection info via _DB_DATAOBJECT instead
194 // of, e.g., calling getDatabaseConnection(), so that we
195 // can avoid infinite loops.
196 global $_DB_DATAOBJECT;
198 if (isset($_DB_DATAOBJECT['CONFIG']['database'])) {
199 $dao = new CRM_Core_DAO();
200 if (isset($_DB_DATAOBJECT['CONNECTIONS'][$dao->_database_dsn_md5
])) {
201 $conn = $_DB_DATAOBJECT['CONNECTIONS'][$dao->_database_dsn_md5
];
203 // FIXME: Polymorphism for the win.
204 if ($conn instanceof DB_mysqli
) {
205 $link = $conn->connection
;
206 if (mysqli_error($link)) {
207 $mysql_error = mysqli_error($link) . ', ' . mysqli_errno($link);
208 mysqli_query($link, 'select 1'); // execute a dummy query to clear error stack
211 elseif ($conn instanceof DB_mysql
) {
213 $mysql_error = mysql_error() . ', ' . mysql_errno();
214 mysql_query('select 1'); // execute a dummy query to clear error stack
218 $mysql_error = 'fixme-unknown-db-cxn';
220 $template->assign_by_ref('mysql_code', $mysql_error);
224 $template->assign_by_ref('error', $error);
225 $errorDetails = CRM_Core_Error
::debug('', $error, FALSE);
226 $template->assign_by_ref('errorDetails', $errorDetails);
228 CRM_Core_Error
::debug_var('Fatal Error Details', $error);
229 CRM_Core_Error
::backtrace('backTrace', TRUE);
231 if ($config->initialized
) {
232 $content = $template->fetch('CRM/common/fatal.tpl');
233 echo CRM_Utils_System
::theme($content);
236 echo "Sorry. A non-recoverable error has occurred. The error trace below might help to resolve the issue<p>";
237 CRM_Core_Error
::debug(NULL, $error);
239 static $runOnce = FALSE;
248 * this function is used to trap and print errors
249 * during system initialization time. Hence the error
250 * message is quite ugly
254 public static function simpleHandler($pearError) {
256 $error = self
::getErrorDetails($pearError);
258 // ensure that debug does not check permissions since we are in bootstrap
259 // mode and need to print a decent message to help the user
260 CRM_Core_Error
::debug('Initialization Error', $error, TRUE, TRUE, FALSE);
262 // always log the backtrace to a file
263 self
::backtrace('backTrace', TRUE);
269 * this function is used to return error details
273 * @return array $error
275 public static function getErrorDetails($pearError) {
276 // create the error array
278 $error['callback'] = $pearError->getCallback();
279 $error['code'] = $pearError->getCode();
280 $error['message'] = $pearError->getMessage();
281 $error['mode'] = $pearError->getMode();
282 $error['debug_info'] = $pearError->getDebugInfo();
283 $error['type'] = $pearError->getType();
284 $error['user_info'] = $pearError->getUserInfo();
285 $error['to_string'] = $pearError->toString();
291 * Handle errors raised using the PEAR Error Stack.
293 * currently the handler just requests the PES framework
294 * to push the error to the stack (return value PEAR_ERRORSTACK_PUSH).
296 * Note: we can do our own error handling here and return PEAR_ERRORSTACK_IGNORE.
298 * Also, if we do not return any value the PEAR_ErrorStack::push() then does the
299 * action of PEAR_ERRORSTACK_PUSHANDLOG which displays the errors on the screen,
300 * since the logger set for this error stack is 'display' - see CRM_Core_Config::getLog();
302 * @param mixed $pearError
306 public static function handlePES($pearError) {
307 return PEAR_ERRORSTACK_PUSH
;
311 * Display an error page with an error message describing what happened.
314 * This is a really annoying function. We ❤ exceptions. Be exceptional!
318 * @param string $message
320 * @param string $code
321 * The error code if any.
322 * @param string $email
323 * The email address to notify of this situation.
327 public static function fatal($message = NULL, $code = NULL, $email = NULL) {
329 'message' => htmlspecialchars($message),
333 if (self
::$modeException) {
335 CRM_Core_Error
::debug_var('Fatal Error Details', $vars);
336 CRM_Core_Error
::backtrace('backTrace', TRUE);
338 $details = 'A fatal error was triggered';
340 $details .= ': ' . $message;
342 throw new Exception($details, $code);
346 $message = ts('We experienced an unexpected error. Please post a detailed description and the backtrace on the CiviCRM forums: %1', array(1 => 'http://forum.civicrm.org/'));
349 if (php_sapi_name() == "cli") {
350 print ("Sorry. A non-recoverable error has occurred.\n$message \n$code\n$email\n\n");
352 echo static::formatBacktrace(debug_backtrace());
354 // FIXME: Why doesn't this call abend()?
355 // Difference: abend() will cleanup transaction and (via civiExit) store session state
356 // self::abend(CRM_Core_Error::FATAL_ERROR);
359 $config = CRM_Core_Config
::singleton();
361 if ($config->fatalErrorHandler
&&
362 function_exists($config->fatalErrorHandler
)
364 $name = $config->fatalErrorHandler
;
367 // the call has been successfully handled
369 self
::abend(CRM_Core_Error
::FATAL_ERROR
);
373 if ($config->backtrace
) {
377 CRM_Core_Error
::debug_var('Fatal Error Details', $vars);
378 CRM_Core_Error
::backtrace('backTrace', TRUE);
380 // If we are in an ajax callback, format output appropriately
381 if (CRM_Utils_Array
::value('snippet', $_REQUEST) === CRM_Core_Smarty
::PRINT_JSON
) {
384 'content' => '<div class="messages status no-popup"><div class="icon inform-icon"></div>' . ts('Sorry but we are not able to provide this at the moment.') . '</div>',
386 if ($config->backtrace
&& CRM_Core_Permission
::check('view debug output')) {
387 $out['backtrace'] = self
::parseBacktrace(debug_backtrace());
388 $message .= '<p><em>See console for backtrace</em></p>';
390 CRM_Core_Session
::setStatus($message, ts('Sorry an error occurred'), 'error');
391 CRM_Core_Transaction
::forceRollbackIfEnabled();
392 CRM_Core_Page_AJAX
::returnJsonResponse($out);
395 $template = CRM_Core_Smarty
::singleton();
396 $template->assign($vars);
397 $config->userSystem
->outputError($template->fetch('CRM/common/fatal.tpl'));
399 self
::abend(CRM_Core_Error
::FATAL_ERROR
);
403 * Display an error page with an error message describing what happened.
405 * This function is evil -- it largely replicates fatal(). Hopefully the
406 * entire CRM_Core_Error system can be hollowed out and replaced with
407 * something that follows a cleaner separation of concerns.
409 * @param Exception $exception
411 public static function handleUnhandledException($exception) {
413 CRM_Utils_Hook
::unhandledException($exception);
415 catch (Exception
$other) {
416 // if the exception-handler generates an exception, then that sucks! oh, well. carry on.
417 CRM_Core_Error
::debug_var('handleUnhandledException_nestedException', self
::formatTextException($other));
419 $config = CRM_Core_Config
::singleton();
421 'message' => $exception->getMessage(),
423 'exception' => $exception,
425 if (!$vars['message']) {
426 $vars['message'] = ts('We experienced an unexpected error. Please post a detailed description and the backtrace on the CiviCRM forums: %1', array(1 => 'http://forum.civicrm.org/'));
430 if (php_sapi_name() == "cli") {
431 printf("Sorry. A non-recoverable error has occurred.\n%s\n", $vars['message']);
432 print self
::formatTextException($exception);
434 // FIXME: Why doesn't this call abend()?
435 // Difference: abend() will cleanup transaction and (via civiExit) store session state
436 // self::abend(CRM_Core_Error::FATAL_ERROR);
439 // Case B: Custom error handler
440 if ($config->fatalErrorHandler
&&
441 function_exists($config->fatalErrorHandler
)
443 $name = $config->fatalErrorHandler
;
446 // the call has been successfully handled
448 self
::abend(CRM_Core_Error
::FATAL_ERROR
);
452 // Case C: Default error handler
455 CRM_Core_Error
::debug_var('Fatal Error Details', $vars, FALSE);
456 CRM_Core_Error
::backtrace('backTrace', TRUE);
459 $template = CRM_Core_Smarty
::singleton();
460 $template->assign($vars);
461 $content = $template->fetch('CRM/common/fatal.tpl');
462 if ($config->backtrace
) {
463 $content = self
::formatHtmlException($exception) . $content;
465 if ($config->userFramework
== 'Joomla' &&
466 class_exists('JError')
468 JError
::raiseError('CiviCRM-001', $content);
471 echo CRM_Utils_System
::theme($content);
475 self
::abend(CRM_Core_Error
::FATAL_ERROR
);
479 * Outputs pre-formatted debug information. Flushes the buffers
480 * so we can interrupt a potential POST/redirect
482 * @param string $name name of debug section
483 * @param $variable mixed reference to variables that we need a trace of
484 * @param bool $log should we log or return the output
485 * @param bool $html whether to generate a HTML-escaped output
486 * @param bool $checkPermission should we check permissions before displaying output
487 * useful when we die during initialization and permissioning
488 * subsystem is not initialized - CRM-13765
491 * the generated output
493 public static function debug($name, $variable = NULL, $log = TRUE, $html = TRUE, $checkPermission = TRUE) {
494 $error = self
::singleton();
496 if ($variable === NULL) {
501 $out = print_r($variable, TRUE);
504 $out = htmlspecialchars($out);
506 $prefix = "<p>$name</p>";
508 $out = "{$prefix}<p><pre>$out</pre></p><p></p>";
512 $prefix = "$name:\n";
514 $out = "{$prefix}$out\n";
518 (!$checkPermission || CRM_Core_Permission
::check('view debug output'))
527 * Similar to the function debug. Only difference is
528 * in the formatting of the output.
530 * @param string $variable_name
531 * @param mixed $variable
533 * Should we use print_r ? (else we use var_dump).
535 * Should we log or return the output.
536 * @param string $comp
540 * the generated output
544 * @see CRM_Core_Error::debug()
545 * @see CRM_Core_Error::debug_log_message()
547 public static function debug_var(
554 // check if variable is set
555 if (!isset($variable)) {
556 $out = "\$$variable_name is not set";
560 $out = print_r($variable, TRUE);
561 $out = "\$$variable_name = $out";
567 $dump = ob_get_contents();
569 $out = "\n\$$variable_name = $dump";
571 // reset if it is an array
572 if (is_array($variable)) {
576 return self
::debug_log_message($out, FALSE, $comp);
580 * Display the error message on terminal and append it to the log file.
582 * Provided the user has the 'view debug output' the output should be displayed. In all
583 * cases it should be logged.
585 * @param string $message
587 * Should we log or return the output.
589 * @param string $comp
590 * Message to be output.
591 * @param string $priority
594 * Format of the backtrace
596 public static function debug_log_message($message, $out = FALSE, $comp = '', $priority = NULL) {
597 $config = CRM_Core_Config
::singleton();
599 $file_log = self
::createDebugLogger($comp);
600 $file_log->log("$message\n", $priority);
602 $str = '<p/><code>' . htmlspecialchars($message) . '</code>';
603 if ($out && CRM_Core_Permission
::check('view debug output')) {
608 if (!empty($config->userFrameworkLogging
)) {
609 // should call $config->userSystem->logger($message) here - but I got a situation where userSystem was not an object - not sure why
610 if ($config->userSystem
->is_drupal
and function_exists('watchdog')) {
611 watchdog('civicrm', '%message', array('%message' => $message), WATCHDOG_DEBUG
);
619 * Append to the query log (if enabled)
621 * @param string $string
623 public static function debug_query($string) {
624 if (defined('CIVICRM_DEBUG_LOG_QUERY')) {
625 if (CIVICRM_DEBUG_LOG_QUERY
=== 'backtrace') {
626 CRM_Core_Error
::backtrace($string, TRUE);
628 elseif (CIVICRM_DEBUG_LOG_QUERY
) {
629 CRM_Core_Error
::debug_var('Query', $string, TRUE, TRUE, 'sql_log');
635 * Execute a query and log the results.
637 * @param string $query
639 public static function debug_query_result($query) {
640 $results = CRM_Core_DAO
::executeQuery($query)->fetchAll();
641 CRM_Core_Error
::debug_var('dao result', array('query' => $query, 'results' => $results));
645 * Obtain a reference to the error log.
647 * @param string $prefix
651 public static function createDebugLogger($prefix = '') {
652 self
::generateLogFileName($prefix);
653 return Log
::singleton('file', \Civi
::$statics[__CLASS__
]['logger_file' . $prefix], '');
657 * Generate a hash for the logfile.
661 * @param CRM_Core_Config $config
665 public static function generateLogFileHash($config) {
666 // Use multiple (but stable) inputs for hash information.
668 defined('CIVICRM_SITE_KEY') ? CIVICRM_SITE_KEY
: 'NO_SITE_KEY',
669 $config->userFrameworkBaseURL
,
673 // Trim 8 chars off the string, make it slightly easier to find
674 // but reveals less information from the hash.
675 return substr(md5(var_export($md5inputs, 1)), 8);
679 * Generate the name of the logfile to use and store it as a static.
681 * This function includes poor man's log file management and a check as to whether the file exists.
683 * @param string $prefix
685 protected static function generateLogFileName($prefix) {
686 if (!isset(\Civi
::$statics[__CLASS__
]['logger_file' . $prefix])) {
687 $config = CRM_Core_Config
::singleton();
689 $prefixString = $prefix ?
($prefix . '.') : '';
691 $hash = self
::generateLogFileHash($config);
692 $fileName = $config->configAndLogDir
. 'CiviCRM.' . $prefixString . $hash . '.log';
694 // Roll log file monthly or if greater than 256M
695 // note that PHP file functions have a limit of 2G and hence
696 // the alternative was introduce
697 if (file_exists($fileName)) {
698 $fileTime = date("Ym", filemtime($fileName));
699 $fileSize = filesize($fileName);
700 if (($fileTime < date('Ym')) ||
701 ($fileSize > 256 * 1024 * 1024) ||
705 $fileName . '.' . date('YmdHi')
709 \Civi
::$statics[__CLASS__
]['logger_file' . $prefix] = $fileName;
717 public static function backtrace($msg = 'backTrace', $log = FALSE) {
718 $backTrace = debug_backtrace();
719 $message = self
::formatBacktrace($backTrace);
721 CRM_Core_Error
::debug($msg, $message);
724 CRM_Core_Error
::debug_var($msg, $message);
729 * Render a backtrace array as a string.
731 * @param array $backTrace
732 * Array of stack frames.
733 * @param bool $showArgs
734 * TRUE if we should try to display content of function arguments (which could be sensitive); FALSE to display only the type of each function argument.
735 * @param int $maxArgLen
736 * Maximum number of characters to show from each argument string.
738 * printable plain-text
740 public static function formatBacktrace($backTrace, $showArgs = TRUE, $maxArgLen = 80) {
742 foreach (self
::parseBacktrace($backTrace, $showArgs, $maxArgLen) as $idx => $trace) {
743 $message .= sprintf("#%s %s\n", $idx, $trace);
745 $message .= sprintf("#%s {main}\n", 1 +
$idx);
750 * Render a backtrace array as an array.
752 * @param array $backTrace
753 * Array of stack frames.
754 * @param bool $showArgs
755 * TRUE if we should try to display content of function arguments (which could be sensitive); FALSE to display only the type of each function argument.
756 * @param int $maxArgLen
757 * Maximum number of characters to show from each argument string.
759 * @see debug_backtrace
760 * @see Exception::getTrace()
762 public static function parseBacktrace($backTrace, $showArgs = TRUE, $maxArgLen = 80) {
764 foreach ($backTrace as $trace) {
766 $fnName = CRM_Utils_Array
::value('function', $trace);
767 $className = isset($trace['class']) ?
($trace['class'] . $trace['type']) : '';
769 // Do not show args for a few password related functions
770 $skipArgs = ($className == 'DB::' && $fnName == 'connect') ?
TRUE : FALSE;
772 if (!empty($trace['args'])) {
773 foreach ($trace['args'] as $arg) {
774 if (!$showArgs ||
$skipArgs) {
775 $args[] = '(' . gettype($arg) . ')';
778 switch ($type = gettype($arg)) {
780 $args[] = $arg ?
'TRUE' : 'FALSE';
789 $args[] = '"' . CRM_Utils_String
::ellipsify(addcslashes((string) $arg, "\r\n\t\""), $maxArgLen) . '"';
793 $args[] = '(Array:' . count($arg) . ')';
797 $args[] = 'Object(' . get_class($arg) . ')';
801 $args[] = 'Resource';
817 CRM_Utils_Array
::value('file', $trace, '[internal function]'),
818 CRM_Utils_Array
::value('line', $trace, ''),
828 * Render an exception as HTML string.
830 * @param Exception $e
832 * printable HTML text
834 public static function formatHtmlException(Exception
$e) {
837 // Exception metadata
839 // Exception backtrace
840 if ($e instanceof PEAR_Exception
) {
842 while (is_callable(array($ei, 'getCause'))) {
843 if ($ei->getCause() instanceof PEAR_Error
) {
844 $msg .= '<table class="crm-db-error">';
845 $msg .= sprintf('<thead><tr><th>%s</th><th>%s</th></tr></thead>', ts('Error Field'), ts('Error Value'));
847 foreach (array('Type', 'Code', 'Message', 'Mode', 'UserInfo', 'DebugInfo') as $f) {
848 $msg .= sprintf('<tr><td>%s</td><td>%s</td></tr>', $f, call_user_func(array($ei->getCause(), "get$f")));
850 $msg .= '</tbody></table>';
852 $ei = $ei->getCause();
854 $msg .= $e->toHtml();
857 $msg .= '<p><b>' . get_class($e) . ': "' . htmlentities($e->getMessage()) . '"</b></p>';
858 $msg .= '<pre>' . htmlentities(self
::formatBacktrace($e->getTrace())) . '</pre>';
864 * Write details of an exception to the log.
866 * @param Exception $e
868 * printable plain text
870 public static function formatTextException(Exception
$e) {
871 $msg = get_class($e) . ": \"" . $e->getMessage() . "\"\n";
874 while (is_callable(array($ei, 'getCause'))) {
875 if ($ei->getCause() instanceof PEAR_Error
) {
876 foreach (array('Type', 'Code', 'Message', 'Mode', 'UserInfo', 'DebugInfo') as $f) {
877 $msg .= sprintf(" * ERROR %s: %s\n", strtoupper($f), call_user_func(array($ei->getCause(), "get$f")));
880 $ei = $ei->getCause();
882 $msg .= self
::formatBacktrace($e->getTrace());
889 * @param string $level
890 * @param array $params
894 public static function createError($message, $code = 8000, $level = 'Fatal', $params = NULL) {
895 $error = CRM_Core_Error
::singleton();
896 $error->push($code, $level, array($params), $message);
901 * Set a status message in the session, then bounce back to the referrer.
903 * @param string $status
904 * The status message to set.
906 * @param null $redirect
907 * @param string $title
909 public static function statusBounce($status, $redirect = NULL, $title = NULL) {
910 $session = CRM_Core_Session
::singleton();
912 $redirect = $session->readUserContext();
914 if ($title === NULL) {
915 $title = ts('Error');
917 $session->setStatus($status, $title, 'alert', array('expires' => 0));
918 if (CRM_Utils_Array
::value('snippet', $_REQUEST) === CRM_Core_Smarty
::PRINT_JSON
) {
919 CRM_Core_Page_AJAX
::returnJsonResponse(array('status' => 'error'));
921 CRM_Utils_System
::redirect($redirect);
925 * Reset the error stack.
928 public static function reset() {
929 $error = self
::singleton();
930 $error->_errors
= array();
931 $error->_errorsByLevel
= array();
935 * PEAR error-handler which converts errors to exceptions
938 * @throws PEAR_Exception
940 public static function exceptionHandler($pearError) {
941 CRM_Core_Error
::debug_var('Fatal Error Details', self
::getErrorDetails($pearError));
942 CRM_Core_Error
::backtrace('backTrace', TRUE);
943 throw new PEAR_Exception($pearError->getMessage(), $pearError);
947 * PEAR error-handler to quietly catch otherwise fatal errors. Intended for use with smtp transport.
950 * The PEAR_ERROR object.
954 public static function nullHandler($obj) {
955 CRM_Core_Error
::debug_log_message("Ignoring exception thrown by nullHandler: {$obj->code}, {$obj->message}");
956 CRM_Core_Error
::backtrace('backTrace', TRUE);
962 * This function is no longer used by v3 api.
963 * @fixme Some core files call it but it should be re-thought & renamed or removed
971 public static function &createAPIError($msg, $data = NULL) {
972 if (self
::$modeException) {
973 throw new Exception($msg, $data);
978 $values['is_error'] = 1;
979 $values['error_message'] = $msg;
981 $values = array_merge($values, $data);
989 public static function movedSiteError($file) {
990 $url = CRM_Utils_System
::url('civicrm/admin/setting/updateConfigBackend',
994 echo "We could not write $file. Have you moved your site directory or server?<p>";
995 echo "Please fix the setting by running the <a href=\"$url\">update config script</a>";
1000 * Terminate execution abnormally.
1002 * @param string $code
1004 protected static function abend($code) {
1005 // do a hard rollback of any pending transactions
1006 // if we've come here, its because of some unexpected PEAR errors
1007 CRM_Core_Transaction
::forceRollbackIfEnabled();
1008 CRM_Utils_System
::civiExit($code);
1012 * @param array $error
1017 public static function isAPIError($error, $type = CRM_Core_Error
::FATAL_ERROR
) {
1018 if (is_array($error) && !empty($error['is_error'])) {
1019 $code = $error['error_message']['code'];
1020 if ($code == $type) {
1029 $e = new PEAR_ErrorStack('CRM');
1030 $e->singleton('CRM', FALSE, NULL, 'CRM_Core_Error');