Browse Source

Added some better fault tolerance if a bad table is given to the chado generate var function

spficklin 12 years ago
parent
commit
e1a399686c
1 changed files with 11 additions and 5 deletions
  1. 11 5
      tripal_core/api/tripal_core.api.inc

+ 11 - 5
tripal_core/api/tripal_core.api.inc

@@ -1421,6 +1421,15 @@ function tripal_core_generate_chado_var($table, $values, $base_options = array()
 
   // get description for the current table----------------------------------------------------------
   $table_desc = tripal_core_get_chado_table_schema($table);
+  if (!$table_desc) {
+    watchdog('tripal_core', "tripal_core_generate_chado_var: The table '%table' has not been defined. ".
+             "and cannot be expanded. If this is a custom table, please add it using the Tripal ".
+             "custom table interface.", array('%table' => $table), WATCHDOG_ERROR);
+    if ($return_array) {
+    	return array();
+    }
+    return FALSE;
+  }
   $table_primary_key = $table_desc['primary key'][0];
   $table_columns = array_keys($table_desc['fields']);
 
@@ -1698,11 +1707,8 @@ function tripal_core_expand_chado_vars($object, $type, $to_expand, $table_option
         }
       }
       else {
-        watchdog(
-          'tripal_core',
-          'tripal_core_expand_chado_vars: Field (%field) not in the right format. It should be <tablename>.<fieldname>',
-        WATCHDOG_ERROR
-        );
+        watchdog('tripal_core', 'tripal_core_expand_chado_vars: Field (%field) not in the right format. ".
+          "It should be <tablename>.<fieldname>', WATCHDOG_ERROR);
       }
       break;
     case "table": //--------------------------------------------------------------------------------