You are here

function patterns_error_get_last in Patterns 7

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

Check and report PHP errors during patterns execution.

Parameters

$op: Operation within hook_patterns() during which the error occurred.

$key: Number of the actions currently proccessed.

$description: Description of the current action.

$pattern_title: Title of the pattern currently proccessed.

$pattern_file: Path to pattern file currently proccessed.

Return value

Error message if new error encountered, FALSE if there are no new errors.

File

includes/error.inc, line 100
Error handling.

Code

function patterns_error_get_last($op, $key, $description, $pattern_title, $pattern_file) {
  $error = patterns_error_last();

  // TODO: t()?
  if (!empty($error) && $error['message'] != 'patterns_error') {
    $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,
      ),
    );
    $php_error_message = $types[$error['type']][0] . ': ' . $error['message'] . ' in ' . $error['file'] . ' on line ' . $error['line'] . '.';
    $message = t('Pattern %title (%pattern_file)<br/>Action #%key: %description (op "%op")<br/>PHP error occurred:<br/>%error', array(
      '%key' => $key,
      '%title' => $pattern_title,
      '%op' => $op,
      '%description' => $description,
      '%error' => $php_error_message,
      '%pattern_file' => $pattern_file,
    ));
    return $message;
  }
  return FALSE;
}