Skip to content

Commit 40e0f7e

Browse files
committed
Improved elm server error handling
1 parent 8df12a7 commit 40e0f7e

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

docs/src/en/updates.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
`type="orthologs"` is now the default, removing the need to specify the `type` argument when calling orthologs
99
- [`gget diamond`](diamond.md):
1010
Now supports translated alignment of nucleotide sequences to amino acid reference sequences using the `--translated` flag.
11+
- [`gget elm`](elm.md):
12+
Improved server error handling.
1113

1214
**Version ≥ 0.29.0** (Sep 25, 2024):
1315
- **New modules:**

gget/gget_setup.py

+23-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
import subprocess
66
import platform
77
import uuid
8-
from platform import python_version
98

10-
from .utils import set_up_logger
9+
from .utils import set_up_logger, check_file_for_error_message
1110

1211
logger = set_up_logger()
1312

@@ -183,28 +182,48 @@ def setup(module, verbose=True, out=None):
183182

184183
# Check if files are present
185184
if os.path.exists(elm_instances_fasta):
185+
# Check that file does not just contain an error message
186+
check_file_for_error_message(
187+
elm_instances_fasta,
188+
"ELM instances fasta file",
189+
ELM_INSTANCES_FASTA_DOWNLOAD,
190+
)
186191
if verbose:
187192
logger.info(f"ELM sequences file present.")
188193
else:
189194
logger.error("ELM FASTA file missing.")
190195

191196
if os.path.exists(elm_classes_tsv):
197+
# Check that file does not just contain an error message
198+
check_file_for_error_message(
199+
elm_classes_tsv, "ELM classes tsv file", ELM_CLASSES_TSV_DOWNLOAD
200+
)
192201
if verbose:
193202
logger.info("ELM classes file present.")
194203
else:
195204
logger.error("ELM classes file missing.")
196205

197206
if os.path.exists(elm_instances_tsv):
207+
# Check that file does not just contain an error message
208+
check_file_for_error_message(
209+
elm_instances_tsv, "ELM instances tsv file", ELM_INSTANCES_TSV_DOWNLOAD
210+
)
198211
if verbose:
199212
logger.info("ELM instances file present.")
200213
else:
201214
logger.error("ELM instances file missing.")
202215

203216
if os.path.exists(elm_intdomains_tsv):
217+
# Check that file does not just contain an error message
218+
check_file_for_error_message(
219+
elm_intdomains_tsv,
220+
"ELM interaction domains tsv file",
221+
ELM_INTDOMAINS_TSV_DOWNLOAD,
222+
)
204223
if verbose:
205-
logger.info("ELM interactions domains file present.")
224+
logger.info("ELM interaction domains file present.")
206225
else:
207-
logger.error("ELM interactions domains file missing.")
226+
logger.error("ELM interaction domains file missing.")
208227

209228
elif module == "alphafold":
210229
if platform.system() == "Windows":

gget/utils.py

+25
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,31 @@ def get_latest_cosmic():
7777
return int(soup.find("div", class_="news").get("id").split("v")[-1])
7878

7979

80+
def check_file_for_error_message(filepath, filename, download_path):
81+
with open(filepath, "r", encoding="utf-8") as file:
82+
content = file.read().strip()
83+
84+
# Define common error indicators
85+
error_keywords = [
86+
"Internal Server Error",
87+
"Bad Gateway",
88+
"Service Unavailable",
89+
"502 Bad Gateway",
90+
"500 Internal Server Error",
91+
]
92+
93+
# Check if the file contains an error message and raise ValueError + print error message if so
94+
if any(keyword in content for keyword in error_keywords):
95+
raise ValueError(
96+
f"""
97+
The {filename} downloaded from {download_path}
98+
contains an error message instead of valid data.\n
99+
Error message:\n{content}\n
100+
Please try again. If the problem persists, please report it here: https://github.com/pachterlab/gget/issues/new?template=issue_report.yml
101+
"""
102+
)
103+
104+
80105
def read_fasta(fasta):
81106
"""
82107
Args:

0 commit comments

Comments
 (0)