4598: catch exceptions more aggressively when looking up pipeline names
authorTim Pierce <twp@clinicalfuture.com>
Tue, 6 Jan 2015 21:21:10 +0000 (21:21 +0000)
committerTim Pierce <twp@clinicalfuture.com>
Tue, 6 Jan 2015 21:21:10 +0000 (21:21 +0000)
Added exception handling for cases where:
* job is not recorded as belonging to any pipeline instance
* pipeline instance has no pipeline template

services/api/script/crunch-failure-report.py

index 5183684324a34b643722f44a44d742b6a1dc7ffc..31ad0fefed821f3c674dc3000d50af6f8d9eec85 100755 (executable)
@@ -90,18 +90,18 @@ def job_user_name(api, user_uuid):
 job_pipeline_names = {}
 def job_pipeline_name(api, job_uuid):
     def _lookup_pipeline_name(api, job_uuid):
-        pipelines = api.pipeline_instances().list(
-            filters='[["components", "like", "%{}%"]]'.format(job_uuid)).execute()
-        if pipelines['items']:
+        try:
+            pipelines = api.pipeline_instances().list(
+                filters='[["components", "like", "%{}%"]]'.format(job_uuid)).execute()
             pi = pipelines['items'][0]
             if pi['name']:
                 return pi['name']
             else:
                 # Use the pipeline template name
                 pt = api.pipeline_templates().get(uuid=pi['pipeline_template_uuid']).execute()
-                if pt:
-                    return pt['name']
-        return ""
+                return pt['name']
+        except (TypeError, ValueError, IndexError):
+            return ""
 
     if job_uuid not in job_pipeline_names:
         job_pipeline_names[job_uuid] = _lookup_pipeline_name(api, job_uuid)