function drush_set_error

8.0.x drush.inc drush_set_error($error, $message = null, $output_label = "")
6.x drush.inc drush_set_error($error, $message = null, $output_label = "")
7.x drush.inc drush_set_error($error, $message = null, $output_label = "")
3.x drush.inc drush_set_error($error, $message = null)
4.x drush.inc drush_set_error($error, $message = null)
5.x drush.inc drush_set_error($error, $message = null, $output_label = "")
master drush.inc drush_set_error($error, $message = null, $output_label = "")

Set an error code for the error handling system.

Parameters

\Drupal\Component\Render\MarkupInterface|string $error: A text string identifying the type of error.

null|string $message: Optional. Error message to be logged. If no message is specified, hook_drush_help will be consulted, using a key of 'error:MY_ERROR_STRING'.

null|string $output_label: Optional. Label to prepend to the error message.

Return value

bool Always returns FALSE, to allow returning false in the calling functions, such as <code>return drush_set_error('DRUSH_FRAMEWORK_ERROR')</code>.

Related topics

169 calls to drush_set_error()
BaseBoot::report_command_error in lib/Drush/Boot/BaseBoot.php
Called by Drush if a command is not found, or if the command was found, but did not meet requirements.
core_watchdog_query in commands/core/watchdog.drush.inc
Build a WHERE snippet based on given parameters.
DrupalBoot::bootstrap_drupal_login in lib/Drush/Boot/DrupalBoot.php
Log into the bootstrapped Drupal site with a specific username or user id.
DrupalBoot::bootstrap_drupal_root_validate in lib/Drush/Boot/DrupalBoot.php
Validate the DRUSH_BOOTSTRAP_DRUPAL_ROOT phase.
DrushBatchContext::offsetSet in includes/batch.inc

... See full list

File

includes/drush.inc, line 1505
The drush API implementation and helpers.

Code

function drush_set_error($error, $message = null, $output_label = "") {
  $error_code = &drush_get_context('DRUSH_ERROR_CODE', DRUSH_SUCCESS);
  $error_code = DRUSH_FRAMEWORK_ERROR;

  $error_log = &drush_get_context('DRUSH_ERROR_LOG', array());

  if (is_numeric($error)) {
    $error = 'DRUSH_FRAMEWORK_ERROR';
  }
  elseif (!is_string($error)) {
    // Typical case: D8 TranslatableMarkup, implementing MarkupInterface.
    $error = "$error";
  }

  $message = ($message) ? $message : drush_command_invoke_all('drush_help', 'error:' . $error);

  if (is_array($message)) {
    $message = implode("\n", $message);
  }

  $error_log[$error][] = $message;
  if (!drush_backend_packet('set_error', array('error' => $error, 'message' => $message))) {
    drush_log(($message) ? $output_label . $message : $output_label . $error, LogLevel::ERROR, $error);
  }

  return FALSE;
}