123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- <?php
- function drupal_error_levels() {
- $types = array(
- E_ERROR => array('Error', WATCHDOG_ERROR),
- E_WARNING => array('Warning', WATCHDOG_WARNING),
- E_PARSE => array('Parse error', WATCHDOG_ERROR),
- E_NOTICE => array('Notice', WATCHDOG_NOTICE),
- E_CORE_ERROR => array('Core error', WATCHDOG_ERROR),
- E_CORE_WARNING => array('Core warning', WATCHDOG_WARNING),
- E_COMPILE_ERROR => array('Compile error', WATCHDOG_ERROR),
- E_COMPILE_WARNING => array('Compile warning', WATCHDOG_WARNING),
- E_USER_ERROR => array('User error', WATCHDOG_ERROR),
- E_USER_WARNING => array('User warning', WATCHDOG_WARNING),
- E_USER_NOTICE => array('User notice', WATCHDOG_NOTICE),
- E_STRICT => array('Strict warning', WATCHDOG_DEBUG),
- E_RECOVERABLE_ERROR => array('Recoverable fatal error', WATCHDOG_ERROR),
- );
-
- if (defined('E_DEPRECATED')) {
- $types[E_DEPRECATED] = array('Deprecated function', WATCHDOG_DEBUG);
- $types[E_USER_DEPRECATED] = array('User deprecated function', WATCHDOG_DEBUG);
- }
- return $types;
- }
- function _drupal_error_handler_real($error_level, $message, $filename, $line, $context) {
- if ($error_level & error_reporting()) {
- $types = drupal_error_levels();
- list($severity_msg, $severity_level) = $types[$error_level];
- $caller = _drupal_get_last_caller(debug_backtrace());
- if (!function_exists('filter_xss_admin')) {
- require_once DRUPAL_ROOT . '/includes/common.inc';
- }
-
- _drupal_log_error(array(
- '%type' => isset($types[$error_level]) ? $severity_msg : 'Unknown error',
-
-
- '!message' => filter_xss_admin($message),
- '%function' => $caller['function'],
- '%file' => $caller['file'],
- '%line' => $caller['line'],
- 'severity_level' => $severity_level,
- ), $error_level == E_RECOVERABLE_ERROR);
- }
- }
- function _drupal_decode_exception($exception) {
- $message = $exception->getMessage();
- $backtrace = $exception->getTrace();
-
- array_unshift($backtrace, array('line' => $exception->getLine(), 'file' => $exception->getFile()));
-
-
- if ($exception instanceof PDOException) {
-
-
-
- $db_functions = array('db_query', 'db_query_range');
- while (!empty($backtrace[1]) && ($caller = $backtrace[1]) &&
- ((isset($caller['class']) && (strpos($caller['class'], 'Query') !== FALSE || strpos($caller['class'], 'Database') !== FALSE || strpos($caller['class'], 'PDO') !== FALSE)) ||
- in_array($caller['function'], $db_functions))) {
-
- array_shift($backtrace);
- }
- if (isset($exception->query_string, $exception->args)) {
- $message .= ": " . $exception->query_string . "; " . print_r($exception->args, TRUE);
- }
- }
- $caller = _drupal_get_last_caller($backtrace);
- return array(
- '%type' => get_class($exception),
-
-
- '!message' => check_plain($message),
- '%function' => $caller['function'],
- '%file' => $caller['file'],
- '%line' => $caller['line'],
- 'severity_level' => WATCHDOG_ERROR,
- );
- }
- function _drupal_render_exception_safe($exception) {
- return check_plain(strtr('%type: !message in %function (line %line of %file).', _drupal_decode_exception($exception)));
- }
- function error_displayable($error = NULL) {
- $error_level = variable_get('error_level', ERROR_REPORTING_DISPLAY_ALL);
- $updating = (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update');
- $all_errors_displayed = ($error_level == ERROR_REPORTING_DISPLAY_ALL);
- $error_needs_display = ($error_level == ERROR_REPORTING_DISPLAY_SOME &&
- isset($error) && $error['%type'] != 'Notice' && $error['%type'] != 'Strict warning');
- return ($updating || $all_errors_displayed || $error_needs_display);
- }
- function _drupal_log_error($error, $fatal = FALSE) {
-
-
- if ($fatal && (drupal_get_bootstrap_phase() != DRUPAL_BOOTSTRAP_FULL)) {
- unset($GLOBALS['theme']);
- if (!defined('MAINTENANCE_MODE')) {
- define('MAINTENANCE_MODE', 'error');
- }
- drupal_maintenance_theme();
- }
-
-
- $test_info = &$GLOBALS['drupal_test_info'];
- if (!empty($test_info['in_child_site']) && !headers_sent() && (!defined('SIMPLETEST_COLLECT_ERRORS') || SIMPLETEST_COLLECT_ERRORS)) {
-
-
- static $number = 0;
- $assertion = array(
- $error['!message'],
- $error['%type'],
- array(
- 'function' => $error['%function'],
- 'file' => $error['%file'],
- 'line' => $error['%line'],
- ),
- );
- header('X-Drupal-Assertion-' . $number . ': ' . rawurlencode(serialize($assertion)));
- $number++;
- }
- watchdog('php', '%type: !message in %function (line %line of %file).', $error, $error['severity_level']);
- if ($fatal) {
- drupal_add_http_header('Status', '500 Service unavailable (with message)');
- }
- if (drupal_is_cli()) {
- if ($fatal) {
-
- print html_entity_decode(strip_tags(t('%type: !message in %function (line %line of %file).', $error))). "\n";
- exit;
- }
- }
- if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
- if ($fatal) {
- if (error_displayable($error)) {
-
- print t('%type: !message in %function (line %line of %file).', $error);
- }
- exit;
- }
- }
- else {
-
-
- if (error_displayable($error)) {
- $class = 'error';
-
-
- if ($error['%type'] == 'User notice') {
- $error['%type'] = 'Debug';
- $class = 'status';
- }
- drupal_set_message(t('%type: !message in %function (line %line of %file).', $error), $class);
- }
- if ($fatal) {
- drupal_set_title(t('Error'));
-
-
- print theme('maintenance_page', array('content' => t('The website encountered an unexpected error. Please try again later.')));
- exit;
- }
- }
- }
- function _drupal_get_last_caller($backtrace) {
-
-
- $blacklist = array('debug', '_drupal_error_handler', '_drupal_exception_handler');
- while (($backtrace && !isset($backtrace[0]['line'])) ||
- (isset($backtrace[1]['function']) && in_array($backtrace[1]['function'], $blacklist))) {
- array_shift($backtrace);
- }
-
-
- $call = $backtrace[0];
-
- if (isset($backtrace[1])) {
- if (isset($backtrace[1]['class'])) {
- $call['function'] = $backtrace[1]['class'] . $backtrace[1]['type'] . $backtrace[1]['function'] . '()';
- }
- else {
- $call['function'] = $backtrace[1]['function'] . '()';
- }
- }
- else {
- $call['function'] = 'main()';
- }
- return $call;
- }
|