function tripal_report_error

2.x tripal_core.tripal.api.inc tripal_report_error($type, $severity, $message, $variables = array(), $options = array())

Provide better error notice for Tripal. If the environment variable 'TRIPAL_DEBUG' is set to 1 then this function will add backtrace information to the message.

Parameters

$type: The catagory to which this message belongs. Can be any string, but the general practice is to use the name of the module.

$severity: The severity of the message; one of the following values:

$message: The message to store in the log. Keep $message translatable by not concatenating dynamic values into it! Variables in the message should be added by using placeholder strings alongside the variables argument to declare the value of the placeholders. See t() for documentation on how $message and $variables interact.

$variables: Array of variables to replace in the message on display or NULL if message is already translated or not possible to translate.

$options: An array of options. Some available options include:

  • print: prints the error message to the terminal screen. Useful when display is the command-line

Related topics

284 calls to tripal_report_error()
chado_add_admin_form_set_title in tripal_core/api/tripal_core.chado_nodes.title_and_path.api.inc
Generic "Set Node Title" sub-form for setting the title of any chado node
chado_add_admin_form_set_url in tripal_core/api/tripal_core.chado_nodes.title_and_path.api.inc
Generic "Set Node URL" sub-form for setting the url of any chado node
chado_add_node_form_properties in tripal_core/api/tripal_core.chado_nodes.properties.api.inc
chado_add_node_form_relationships in tripal_core/api/tripal_core.chado_nodes.relationships.api.inc
Provides a form for adding to BASE_relationship and relationship tables
chado_analysis_insert in tripal_analysis/includes/tripal_analysis.chado_node.inc
Implements hook_insert(). When a new chado_analysis node is created we also need to add information to our chado_analysis table. This function is called on insert of a new node of type 'chado_analysis' and inserts the necessary information.

... See full list

1 string reference to 'tripal_report_error'
tripal_core_report_error in tripal_core/api/tripal_core.DEPRECATED.api.inc
@todo Remove. This was not in Tripal 1.x.

File

tripal_core/api/tripal_core.tripal.api.inc, line 75
Provides an application programming interface (API) for Tripal

Code

function tripal_report_error($type, $severity, $message, $variables = array(), $options = array()) {

  // Get human-readable severity string
  $severity_string = '';
  switch ($severity) {
    case TRIPAL_CRITICAL:
      $severity_string = 'CRITICAL';
      break;
    case TRIPAL_ERROR:
      $severity_string = 'ERROR';
      break;
    case TRIPAL_WARNING:
      $severity_string = 'WARNING';
      break;
    case TRIPAL_NOTICE:
      $severity_string = 'NOTICE';
      break;
    case TRIPAL_INFO:
      $severity_string = 'INFO';
      break;
    case TRIPAL_DEBUG:
      $severity_string = 'DEBUG';
      break;
  }

  // If we are not set to return debugging information and the severity string is debug
  // then don't report the error.
  if (($severity == TRIPAL_DEBUG) AND (getenv('TRIPAL_DEBUG') != 1)) {
    return FALSE;
  }

  // get the backtrace and include in the error message, but only if the
  // TRIPAL_DEBUG environment variable is set.
  if (getenv('TRIPAL_DEBUG') == 1) {
    $backtrace = debug_backtrace();
    $message .= "\nBacktrace:\n";
    $i = 1;
    for ($i = 1; $i < count($backtrace); $i++) {
      $function = $backtrace[$i];
      $message .= "  $i) " . $function['function'] . "\n";
    }
  }

  // Send to watchdog.
  try {
    watchdog($type, $message, $variables, $severity);
  }
  catch (Exception $e) {
    print "CRITICAL (TRIPAL_CORE): Unable to register error message with watchdog: " . $e->getMessage() . "\n.";
    $options['print'] = TRUE;
  }

  // Format the message for printing (either to the screen, log or both)
  if (sizeof($variables) > 0) {
    $print_message = str_replace(array_keys($variables), $variables, $message);
  }
  else {
    $print_message = $message;
  }

  // If print option supplied then print directly to the screen.
  if (isset($options['print'])) {
    print $severity_string . ' (' . strtoupper($type) . '): ' . $print_message . "\n";
  }

  // Print to the Tripal error log but only if the severity is not info.
  if (($severity != TRIPAL_INFO)) {
    tripal_log('[' . strtoupper($type) . '] ' . $print_message . "\n", $severity_string);
  }
}