function tripal_report_error

2.x 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.


$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/
Generic "Set Node Title" sub-form for setting the title of any chado node
chado_add_admin_form_set_url in tripal_core/api/
Generic "Set Node URL" sub-form for setting the url of any chado node
chado_add_node_form_properties in tripal_core/api/
chado_add_node_form_relationships in tripal_core/api/
Provides a form for adding to BASE_relationship and relationship tables
chado_analysis_insert in tripal_analysis/includes/
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/
@todo Remove. This was not in Tripal 1.x.


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


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

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

  // 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);