From f80b83bdea94a1f5c23a93ba9c987a496dd9f22f Mon Sep 17 00:00:00 2001 From: paulzierep Date: Tue, 5 Nov 2024 10:06:03 +0100 Subject: [PATCH] catch workflowhub error --- sources/README.md | 4 ++-- sources/bin/extract_galaxy_workflows.py | 13 ++++++++++--- sources/bin/shared.py | 14 +++++++++++--- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/sources/README.md b/sources/README.md index 52fd7657..6d353ea7 100644 --- a/sources/README.md +++ b/sources/README.md @@ -245,13 +245,13 @@ To make a test run of the tool to check its functionalities follow [Usage](#Usag 1. Workflow extraction ```bash - $ bash bin/extract_all_workflows.sh test + $ bash sources/bin/extract_all_workflows.sh test ``` 2. Workflow filtering ```bash - $ bash bin/get_community_workflowss.sh test + $ bash sources/bin/get_community_workflows.sh test ``` # Galaxy Labs framework diff --git a/sources/bin/extract_galaxy_workflows.py b/sources/bin/extract_galaxy_workflows.py index 4ff03f75..cbde094f 100644 --- a/sources/bin/extract_galaxy_workflows.py +++ b/sources/bin/extract_galaxy_workflows.py @@ -156,9 +156,10 @@ def add_workflows_from_workflowhub(self) -> None: f"https://workflowhub.eu{wf['links']['self']}", header, ) - wf = Workflow() - wf.init_from_search(wf=wfhub_wf, source="WorkflowHub", tools=self.tools) - self.workflows.append(wf) + if wfhub_wf: + wf = Workflow() + wf.init_from_search(wf=wfhub_wf, source="WorkflowHub", tools=self.tools) + self.workflows.append(wf) print(len(self.workflows)) def add_workflows_from_a_server(self, server: str) -> None: @@ -170,6 +171,12 @@ def add_workflows_from_a_server(self, server: str) -> None: f"{server}/api/workflows/", header, ) + + # test max 50 wfs + if self.test: + if len(server_wfs) > 50: + server_wfs = server_wfs[:50] + count = 0 for wf in server_wfs: if wf["published"] and wf["importable"] and not wf["deleted"] and not wf["hidden"]: diff --git a/sources/bin/shared.py b/sources/bin/shared.py index 0097bcd8..21c9c108 100644 --- a/sources/bin/shared.py +++ b/sources/bin/shared.py @@ -96,9 +96,17 @@ def get_request_json(url: str, headers: dict) -> dict: :param url: galaxy tool id """ - r = requests.get(url, auth=None, headers=headers) - r.raise_for_status() - return r.json() + + try: + r = requests.get(url, auth=None, headers=headers) + r.raise_for_status() # Optional: Raises an HTTPError if the response was an unsuccessful status code + except ConnectionError as e: + raise ConnectionError("Connection aborted: Remote end closed connection without response") from e + except requests.exceptions.RequestException as e: + # This will handle other possible errors (e.g., timeout, HTTPError) + raise SystemExit(e) + else: + return r.json() def format_date(date: str) -> str: