Skip to content

Commit

Permalink
Handle all requests error in ``ApiBiotoolsMetadataSource._raw_get_met…
Browse files Browse the repository at this point in the history
…adata``

Fix the following traceback when running `planemo lint` if bio.tools is down:

```
File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/galaxy/tool\_util/biotools/source.py", line 69, in get\_biotools\_metadata
return BiotoolsEntry.from\_json(json.loads(content))
^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/json/**init**.py", line 346, in loads
return \_default\_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/json/decoder.py", line 337, in decode
obj, end = self.raw\_decode(s, idx=\_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/json/decoder.py", line 355, in raw\_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
```
  • Loading branch information
nsoranzo committed Jul 8, 2024
1 parent 06590c9 commit 4ac6a1e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/galaxy/tool_util/biotools/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ def __init__(self, cache=None):

def _raw_get_metadata(self, biotools_reference) -> Optional[str]:
api_url = f"https://bio.tools/api/tool/{biotools_reference}?format=json"
req = requests.get(api_url, timeout=DEFAULT_SOCKET_TIMEOUT)
req.encoding = req.apparent_encoding
if req.status_code == 404:
return None
else:
try:
req = requests.get(api_url, timeout=DEFAULT_SOCKET_TIMEOUT)
req.raise_for_status()
req.encoding = req.apparent_encoding
return req.text
except Exception:
return None

def get_biotools_metadata(self, biotools_reference: str) -> Optional[BiotoolsEntry]:
createfunc = functools.partial(self._raw_get_metadata, biotools_reference)
Expand Down

0 comments on commit 4ac6a1e

Please sign in to comment.