function _drush_docs_find_set_error_calls

8.0.x docs.drush.inc _drush_docs_find_set_error_calls(&$error_list, $filename, $shortname)
6.x docs.drush.inc _drush_docs_find_set_error_calls(&$error_list, $filename, $shortname)
7.x docs.drush.inc _drush_docs_find_set_error_calls(&$error_list, $filename, $shortname)
4.x docs.drush.inc _drush_docs_find_set_error_calls(&$error_list, $filename, $shortname)
5.x docs.drush.inc _drush_docs_find_set_error_calls(&$error_list, $filename, $shortname)
master docs.drush.inc _drush_docs_find_set_error_calls(&$error_list, $filename, $shortname)

Search through a php source file looking for calls to the function drush_set_error. If found, and if the first parameter is an uppercase alphanumeric identifier, then record the error code and the error message in our table.

1 call to _drush_docs_find_set_error_calls()
drush_docs_errorcodes in commands/core/docs.drush.inc
docs-errorcodes command. Print a list of all error codes that can be found.

File

commands/core/docs.drush.inc, line 266
Documentation commands providing various topics.

Code

function _drush_docs_find_set_error_calls(&$error_list, $filename, $shortname) {
  $lines = file($filename);
  foreach ($lines as $line) {
    $matches = array();
    // Find the error code after the drush_set_error call.  The error code
    // should consist of uppercase letters and underscores only (numbers thrown in just in case)
    $match_result = preg_match("/.*drush_set_error[^'\"]['\"]([A-Z0-9_]*)['\"][^,]*,[^'\"]*(['\"])/", $line, $matches);
    if ($match_result) {
      $error_code = $matches[1];
      $quote_char = $matches[2];
      $error_message = "";
      $message_start = strlen($matches[0]) - 1;

      // Regex adapted from http://stackoverflow.com/questions/1824325/regex-expression-for-escaped-quoted-string-wont-work-in-phps-preg-match-allif ($quote_char == '"') {
      if ($quote_char == '"') {
        $regex = '/"((?:[^\\\]*?(?:\\\")?)*?)"/';
      }
      else {
        $regex = "/'((?:[^\\\]*?(?:\\\')?)*?)'/";
      }
      $match_result = preg_match($regex, $line, $matches, 0, $message_start);

      if ($match_result) {
        $error_message = $matches[1];
      }
      $error_list[$error_code] = array_key_exists($error_code, $error_list) ? array_merge($error_list[$error_code], array($error_message)) : array($error_message);
    }
  }
}