You are here

function patterns_error_handler in Patterns 7.2

Same name and namespace in other branches
  1. 6.2 patterns.module \patterns_error_handler()
  2. 6 patterns.module \patterns_error_handler()
  3. 7 includes/error.inc \patterns_error_handler()

Custom Patterns error handler.

Custom error handler used only during patterns execution in order to catch and properly handle PHP errors. Based on drupal_error_handler().

1 call to patterns_error_handler()
patterns_sync_form_values in includes/unused.inc
Make some modifications to the form values based on the form In particular, make sure form elements with #options and #multiple set the keys of the array as the key of the value as how FAPI does it, but XML of course does not.
1 string reference to 'patterns_error_handler'
patterns_set_error_handler in includes/error.inc
Sets the custom Patterns error handler.

File

includes/error.inc, line 33
Error handling.

Code

function patterns_error_handler($errno, $message, $filename, $line, $context) {

  // @TODO  E_DEPRECATED does not work in PHP < 5.3
  if ($errno & (E_ALL ^ E_NOTICE)) {

    // ^ E_DEPRECATED)) {
    $types = array(
      1 => array(
        'Error',
        WATCHDOG_ERROR,
      ),
      2 => array(
        'Warning',
        WATCHDOG_WARNING,
      ),
      4 => array(
        'Parse error',
        WATCHDOG_ERROR,
      ),
      8 => array(
        'Notice',
        WATCHDOG_NOTICE,
      ),
      16 => array(
        'Core error',
        WATCHDOG_ERROR,
      ),
      32 => array(
        'Core warning',
        WATCHDOG_WARNING,
      ),
      64 => array(
        'Compile error',
        WATCHDOG_ERROR,
      ),
      128 => array(
        'Compile warning',
        WATCHDOG_WARNING,
      ),
      256 => array(
        'User error',
        WATCHDOG_ERROR,
      ),
      512 => array(
        'User warning',
        WATCHDOG_WARNING,
      ),
      1024 => array(
        'User notice',
        WATCHDOG_NOTICE,
      ),
      2048 => array(
        'Strict warning',
        WATCHDOG_DEBUG,
      ),
      4096 => array(
        'Recoverable fatal error',
        WATCHDOG_ERROR,
      ),
    );

    // For database errors, we want the line number/file name of the place that
    // the query was originally called, not _db_query().
    if (isset($context['DB_ERROR'])) {
      $backtrace = array_reverse(debug_backtrace());

      // List of functions where SQL queries can originate.
      $query_functions = array(
        'db_query',
        'pager_query',
        'db_query_range',
        'db_query_temporary',
        'update_sql',
      );

      // Determine where query function was called, and adjust line/file
      // accordingly.
      foreach ($backtrace as $index => $function) {
        if (in_array($function['function'], $query_functions)) {
          $line = $backtrace[$index]['line'];
          $filename = $backtrace[$index]['file'];
          break;
        }
      }
    }

    // 'patterns_error' is not a real error and should be skipped.
    if ($message != 'patterns_error') {
      watchdog('php', '%message in %file on line %line.', array(
        '%error' => $types[$errno][0],
        '%message' => $message,
        '%file' => $filename,
        '%line' => $line,
      ), $types[$errno][1]);
      if ($types[$errno][1] == WATCHDOG_ERROR) {
        patterns_error_last(array(
          'message' => $message,
          'type' => $errno,
          'file' => $filename,
          'line' => $line,
        ));
      }
    }
  }
  return TRUE;
}