NAL-i5K / tripal_eutils

ncbi loader via the eutils interface
GNU General Public License v3.0
4 stars 3 forks source link

preview and importer need to be more flexible about failure #135

Closed bradfordcondon closed 5 years ago

bradfordcondon commented 5 years ago

attemping to add an assembly of 744358: this is invalid.

However hte formatter throws these errors:

otice: Undefined index: name in EUtilsAssemblyFormatter->formatBaseRecord() (line 39 of /Users/bc/tripal/sites/all/modules/custom/tripal_eutils/includes/formatters/EUtilsAssemblyFormatter.inc).
Notice: Undefined index: description in EUtilsAssemblyFormatter->formatBaseRecord() (line 40 of /Users/bc/tripal/sites/all/modules/custom/tripal_eutils/includes/formatters/EUtilsAssemblyFormatter.inc).
Notice: Undefined index: sourcename in EUtilsAssemblyFormatter->formatBaseRecord() (line 42 of /Users/bc/tripal/sites/all/modules/custom/tripal_eutils/includes/formatters/EUtilsAssemblyFormatter.inc).
Notice: Undefined index: accessions in EUtilsAssemblyFormatter->formatBaseRecord() (line 43 of /Users/bc/tripal/sites/all/modules/custom/tripal_eutils/includes/formatters/EUtilsAssemblyFormatter.inc).
Warning: implode(): Invalid arguments passed in EUtilsAssemblyFormatter->formatBaseRecord() (line 44 of /Users/bc/tripal/sites/all/modules/custom/tripal_eutils/includes/formatters/EUtilsAssemblyFormatter.inc).
Notice: Undefined index: stats in EUtilsAssemblyFormatter->formatAttributes() (line 69 of /Users/bc/tripal/sites/all/modules/custom/tripal_eutils/includes/formatters/EUtilsAssemblyFormatter.inc).
Warning: Invalid argument supplied for foreach() in EUtilsAssemblyFormatter->formatAttributes() (line 69 of /Users/bc/tripal/sites/all/modules/custom/tripal_eutils/includes/formatters/EUtilsAssemblyFormatter.inc).
Notice: Undefined index: files in EUtilsAssemblyFormatter->formatAttributes() (line 72 of /Users/bc/tripal/sites/all/modules/custom/tripal_eutils/includes/formatters/EUtilsAssemblyFormatter.inc).
Warning: Invalid argument supplied for foreach() in EUtilsAssemblyFormatter->formatAttributes() (line 72 of /Users/bc/tripal/sites/all/modules/custom/tripal_eutils/includes/formatters/EUtilsAssemblyFormatter.inc).
Notice: Undefined index: accessions in EUtilsAssemblyFormatter->format() (line 23 of /Users/bc/tripal/sites/all/modules/custom/tripal_eutils/includes/formatters/EUtilsAssemblyFormatter.inc).
TypeError: Argument 1 passed to EUtilsAssemblyFormatter::formatLinkedRecords() must be of the type array, null given, called in /Users/bc/tripal/sites/all/modules/custom/tripal_eutils/includes/formatters/EUtilsAssemblyFormatter.inc on line 23 in EUtilsAssemblyFormatter->formatLinkedRecords() (line 95 of /Users/bc/tripal/sites/all/modules/custom/tripal_eutils/includes/formatters/EUtilsAssemblyFormatter.inc).

I would bet we need the formatters to gracefully fail.

bradfordcondon commented 5 years ago

  $connection = new \EUtils();
  try {
    $connection->setPreview();
    $parsed = $connection->get($db, $accession);
    $form_state['values']['parsed'] = $parsed;
  }
  catch (\Exception $e) {
    tripal_set_message($e, TRIPAL_ERROR);
    return;
  }

i think try/catch just doesn't behave how i think it would. It looks like the validator already handles it gracefully via try/catch....

bradfordcondon commented 5 years ago

ok. i've sussed hte problem. Our EUTils DOES check if the request was successful: if it wasn't it would throw an error, and it gets caught and we have no problems.

  /**
   * Check if the request is successful.
   *
   * @return bool
   *   TRUE for success.
   */
  public function isSuccessful() {
    $status = $this->status();
    return $status >= 200 && $status <= 299;
  }

Unfortunately, that's not what happens, because the response code is 200 for a "no records found" request. So it goes to the parser and the formatter with this empty, bad XML.

So instead, we need to look at the data and see if its an "ERROR" response object:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE eSummaryResult PUBLIC "-//NLM//DTD esummary assembly 20180216//EN" "https://eutils.ncbi.nlm.nih.gov/eutils/dtd/20180216/esummary_assembly.dtd">
<eSummaryResult>
<DocumentSummarySet status="OK">
<DbBuild>Build190205-2205.1</DbBuild>
<DocumentSummary uid="744358">
<error>cannot get document summary</error>
</DocumentSummary>

</DocumentSummarySet>
</eSummaryResult>

if we're lucky, all EUtils requests will return something with an error tag, and that can be how we determine if the request was unsuccessful.

bradfordcondon commented 5 years ago

merged, thank you @almasaeed2010