Skip to content

Commit

Permalink
I mean even more error handling?
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Oct 30, 2024
1 parent 3f14b76 commit 02a817d
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions lib/galaxy/tool_util/verify/interactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,15 +429,30 @@ def publish_history(self, history_id: str) -> None:
def test_data_path(self, tool_id, filename, tool_version=None):
version_fragment = f"&tool_version={tool_version}" if tool_version else ""
response = self._get(f"tools/{tool_id}/test_data_path?filename={filename}{version_fragment}", admin=True)
if response.status_code in [200, 404]:
return response.json()

base_error = "Failed to parse test_data_path from Galaxy. An admin key is required for this feature and it is probably not set or not a valid admin key."
err_msg = GalaxyInteractorApi._append_response_to_err_msg(response, base_error)
raise Exception(err_msg)

@staticmethod
def _append_response_to_err_msg(response: Response, base_error: Optional[str] = None):
try:
result = response.json()
as_json = response.json()
if not isinstance(as_json, dict):
err_msg = f"Failed to parse expected JSON error from API endpoint. Status Code: {response.status_code}. Response JSON: {as_json}"
else:
err_msg = as_json.get(
"err_msg",
f"Unknown error - JSON didn't contain the expected error dictionary with an err_msg key. Status Code: {response.status_code}. Response JSON: {as_json}",
)
except Exception:
raise Exception(
f"Failed to parse test_data_path from Galaxy. An admin key is required for this feature and it is probably not set or not a valid admin key. Status Code: {response.status_code}. Response: {response.text}."
)
if response.status_code in [200, 404]:
return result
raise Exception(result["err_msg"])
err_msg = "Failed to parse expected JSON from API endpoint. Status Code: {response.status_code}. Response: {response.text}"
if base_error is None:
return err_msg
else:
return f"{base_error} {err_msg}"

def test_data_download(self, tool_id, filename, mode="file", is_output=True, tool_version=None):
result = None
Expand Down

0 comments on commit 02a817d

Please sign in to comment.