class CRM_Core_Error extends PEAR_ErrorStack

Class CRM_Core_Error

Constants

FATAL_ERROR

Status code of various types of errors.

DUPLICATE_CONTACT

DUPLICATE_CONTRIBUTION

DUPLICATE_PARTICIPANT

Properties

static $modeException If modeException == true, errors are raised as exception instead of returning civicrm_errors

Methods

static object
singleton(null $package = NULL, bool $msgCallback = FALSE, bool $contextCallback = FALSE, bool $throwPEAR_Error = FALSE, string $stackClass = 'PEAR_ErrorStack')

Singleton function used to manage this object.

__construct()

Constructor.

static array|null|string
getMessages($error, string $separator = '<br />')

No description

static 
displaySessionError($error, string $separator = '<br />')

Status display function specific to payment processor errors.

static 
handle(object $pearError)

Create the main callback method. this method centralizes error processing.

static 
simpleHandler($pearError)

this function is used to trap and print errors during system initialization time. Hence the error message is quite ugly

static array
getErrorDetails($pearError)

this function is used to return error details

static int
handlePES(mixed $pearError)

Handle errors raised using the PEAR Error Stack.

static 
fatal(string $message = NULL, string $code = NULL, string $email = NULL) deprecated

Display an error page with an error message describing what happened.

static 
handleUnhandledException(Exception $exception)

Display an error page with an error message describing what happened.

static string
debug(string $name, $variable = NULL, bool $log = TRUE, bool $html = TRUE, bool $checkPermission = TRUE)

Outputs pre-formatted debug information. Flushes the buffers so we can interrupt a potential POST/redirect

static string
debug_var(string $variable_name, mixed $variable, bool $print = TRUE, bool $log = TRUE, string $prefix = '')

Similar to the function debug. Only difference is in the formatting of the output.

static string
debug_log_message(string $message, bool $out = FALSE, string $prefix = '', string $priority = NULL)

Display the error message on terminal and append it to the log file.

static 
debug_query(string $string)

Append to the query log (if enabled)

static 
debug_query_result(string $query)

Execute a query and log the results.

static Log
createDebugLogger(string $prefix = '')

Obtain a reference to the error log.

static string
generateLogFileHash(CRM_Core_Config $config)

Generate a hash for the logfile.

static 
generateLogFileName(string $prefix)

Generate the name of the logfile to use and store it as a static.

static 
backtrace(string $msg = 'backTrace', bool $log = FALSE)

No description

static string
formatBacktrace(array $backTrace, bool $showArgs = TRUE, int $maxArgLen = 80)

Render a backtrace array as a string.

static array
parseBacktrace(array $backTrace, bool $showArgs = TRUE, int $maxArgLen = 80)

Render a backtrace array as an array.

static string
formatHtmlException( $e)

Render an exception as HTML string.

static string
formatTextException( $e)

Write details of an exception to the log.

static object
createError($message, int $code = 8000, string $level = 'Fatal', array $params = NULL)

No description

static 
statusBounce(string $status, null $redirect = NULL, string $title = NULL)

Set a status message in the session, then bounce back to the referrer.

static 
reset()

Reset the error stack.

static 
exceptionHandler($pearError)

PEAR error-handler which converts errors to exceptions

static object
nullHandler(object $obj)

PEAR error-handler to quietly catch otherwise fatal errors. Intended for use with smtp transport.

static array
createAPIError($msg, null $data = NULL) deprecated

No description

static 
movedSiteError($file)

No description

static 
abend(string $code)

Terminate execution abnormally.

static bool
isAPIError(array $error, int $type = CRM_Core_Error::FATAL_ERROR)

No description

Details

at line 111
static object singleton(null $package = NULL, bool $msgCallback = FALSE, bool $contextCallback = FALSE, bool $throwPEAR_Error = FALSE, string $stackClass = 'PEAR_ErrorStack')

Singleton function used to manage this object.

Parameters

null $package
bool $msgCallback
bool $contextCallback
bool $throwPEAR_Error
string $stackClass

Return Value

object

at line 121
__construct()

Constructor.

at line 142
static array|null|string getMessages($error, string $separator = '<br />')

Parameters

$error
string $separator

Return Value

array|null|string

at line 160
static displaySessionError($error, string $separator = '<br />')

Status display function specific to payment processor errors.

Parameters

$error
string $separator

at line 177
static handle(object $pearError)

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.

Parameters

object $pearError PEAR_Error

at line 254
static simpleHandler($pearError)

this function is used to trap and print errors during system initialization time. Hence the error message is quite ugly

Parameters

$pearError

at line 275
static array getErrorDetails($pearError)

this function is used to return error details

Parameters

$pearError

Return Value

array $error

at line 306
static int handlePES(mixed $pearError)

Handle errors raised using the PEAR Error Stack.

currently the handler just requests the PES framework to push the error to the stack (return value PEAR_ERRORSTACK_PUSH).

Note: we can do our own error handling here and return PEAR_ERRORSTACK_IGNORE.

Also, if we do not return any value the PEAR_ErrorStack::push() then does the action of PEAR_ERRORSTACK_PUSHANDLOG which displays the errors on the screen, since the logger set for this error stack is 'display' - see CRM_Core_Config::getLog();

Parameters

mixed $pearError

Return Value

int

at line 327
static fatal(string $message = NULL, string $code = NULL, string $email = NULL) deprecated

deprecated This is a really annoying function. We ❤ exceptions. Be exceptional!

Display an error page with an error message describing what happened.

Parameters

string $message The error message.
string $code The error code if any.
string $email The email address to notify of this situation.

Exceptions

Exception

See also

CRM-20181

at line 411
static handleUnhandledException(Exception $exception)

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 something that follows a cleaner separation of concerns.

Parameters

Exception $exception

at line 493
static string debug(string $name, $variable = NULL, bool $log = TRUE, bool $html = TRUE, bool $checkPermission = TRUE)

Outputs pre-formatted debug information. Flushes the buffers so we can interrupt a potential POST/redirect

Parameters

string $name name of debug section
$variable mixed reference to variables that we need a trace of
bool $log should we log or return the output
bool $html whether to generate a HTML-escaped output
bool $checkPermission should we check permissions before displaying output useful when we die during initialization and permissioning subsystem is not initialized - CRM-13765

Return Value

string the generated output

at line 547
static string debug_var(string $variable_name, mixed $variable, bool $print = TRUE, bool $log = TRUE, string $prefix = '')

Similar to the function debug. Only difference is in the formatting of the output.

Parameters

string $variable_name Variable name.
mixed $variable Variable value.
bool $print Use print_r (if true) or var_dump (if false).
bool $log Log or return the output?
string $prefix Prefix for output logfile.

Return Value

string The generated output

See also

CRM_Core_Error::debug()
CRM_Core_Error::debug_log_message()

at line 590
static string debug_log_message(string $message, bool $out = FALSE, string $prefix = '', string $priority = NULL)

Display the error message on terminal and append it to the log file.

Provided the user has the 'view debug output' the output should be displayed. In all cases it should be logged.

Parameters

string $message
bool $out Should we log or return the output.
string $prefix Message prefix.
string $priority

Return Value

string Format of the backtrace

at line 625
static debug_query(string $string)

Append to the query log (if enabled)

Parameters

string $string

at line 641
static debug_query_result(string $query)

Execute a query and log the results.

Parameters

string $query

at line 653
static Log createDebugLogger(string $prefix = '')

Obtain a reference to the error log.

Parameters

string $prefix

Return Value

Log

at line 667
static string generateLogFileHash(CRM_Core_Config $config)

Generate a hash for the logfile.

CRM-13640.

Parameters

CRM_Core_Config $config

Return Value

string

at line 687
static protected generateLogFileName(string $prefix)

Generate the name of the logfile to use and store it as a static.

This function includes poor man's log file management and a check as to whether the file exists.

Parameters

string $prefix

at line 719
static backtrace(string $msg = 'backTrace', bool $log = FALSE)

Parameters

string $msg
bool $log

at line 742
static string formatBacktrace(array $backTrace, bool $showArgs = TRUE, int $maxArgLen = 80)

Render a backtrace array as a string.

Parameters

array $backTrace Array of stack frames.
bool $showArgs 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.
int $maxArgLen Maximum number of characters to show from each argument string.

Return Value

string printable plain-text

at line 764
static array parseBacktrace(array $backTrace, bool $showArgs = TRUE, int $maxArgLen = 80)

Render a backtrace array as an array.

Parameters

array $backTrace Array of stack frames.
bool $showArgs 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.
int $maxArgLen Maximum number of characters to show from each argument string.

Return Value

array

See also

debug_backtrace
Exception::getTrace()

at line 836
static string formatHtmlException( $e)

Render an exception as HTML string.

Parameters

$e

Return Value

string printable HTML text

at line 872
static string formatTextException( $e)

Write details of an exception to the log.

Parameters

$e

Return Value

string printable plain text

at line 896
static object createError($message, int $code = 8000, string $level = 'Fatal', array $params = NULL)

Parameters

$message
int $code
string $level
array $params

Return Value

object

at line 911
static statusBounce(string $status, null $redirect = NULL, string $title = NULL)

Set a status message in the session, then bounce back to the referrer.

Parameters

string $status The status message to set.
null $redirect
string $title

at line 930
static reset()

Reset the error stack.

at line 942
static exceptionHandler($pearError)

PEAR error-handler which converts errors to exceptions

Parameters

$pearError

Exceptions

PEAR_Exception

at line 956
static object nullHandler(object $obj)

PEAR error-handler to quietly catch otherwise fatal errors. Intended for use with smtp transport.

Parameters

object $obj The PEAR_ERROR object.

Return Value

object $obj

at line 973
static array createAPIError($msg, null $data = NULL) deprecated

deprecated This function is no longer used by v3 api.

Parameters

$msg
null $data

Return Value

array

Exceptions

Exception

at line 991
static movedSiteError($file)

Parameters

$file

at line 1006
static protected abend(string $code)

Terminate execution abnormally.

Parameters

string $code

at line 1019
static bool isAPIError(array $error, int $type = CRM_Core_Error::FATAL_ERROR)

Parameters

array $error
int $type

Return Value

bool