From 3cb10a4609b9b94c2c01f910bdee6d14cd02b726 Mon Sep 17 00:00:00 2001 From: Harrison Deng Date: Thu, 13 Mar 2025 18:13:38 +0000 Subject: [PATCH] Added client error as acceptable exception --- src/autobigs/engine/analysis/bigsdb.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/autobigs/engine/analysis/bigsdb.py b/src/autobigs/engine/analysis/bigsdb.py index 033ef0a..2abbb2b 100644 --- a/src/autobigs/engine/analysis/bigsdb.py +++ b/src/autobigs/engine/analysis/bigsdb.py @@ -9,7 +9,7 @@ import shutil import tempfile from typing import Any, AsyncGenerator, AsyncIterable, Coroutine, Iterable, Mapping, Sequence, Set, Union -from aiohttp import ClientSession, ClientTimeout, ServerDisconnectedError +from aiohttp import ClientOSError, ClientSession, ClientTimeout, ServerDisconnectedError from autobigs.engine.reading import read_fasta from autobigs.engine.structures.alignment import PairwiseAlignment @@ -100,7 +100,7 @@ class RemoteBIGSdbMLSTProfiler(BIGSdbMLSTProfiler): yield result_allele if isinstance(sequence_string, str) else (sequence_string.name, result_allele) else: raise NoBIGSdbMatchesException(self._database_name, self._scheme_id, sequence_string.name if isinstance(sequence_string, NamedString) else None) - except (ConnectionError, ServerDisconnectedError) as e: # Errors we will retry + except (ConnectionError, ServerDisconnectedError, ClientOSError) as e: # Errors we will retry last_error = e success = False await asyncio.sleep(5) # In case the connection issue is due to rate issues @@ -109,7 +109,7 @@ class RemoteBIGSdbMLSTProfiler(BIGSdbMLSTProfiler): if not success and last_error is not None: try: raise last_error - except (ConnectionError, ServerDisconnectedError) as e: # Non-fatal errors + except (ConnectionError, ServerDisconnectedError, ClientOSError) as e: # Non-fatal errors yield Allele("error", "error", None) async def determine_mlst_st(self, alleles: Union[AsyncIterable[Union[Allele, tuple[str, Allele]]], Iterable[Union[Allele, tuple[str, Allele]]]]) -> Union[MLSTProfile, NamedMLSTProfile]: @@ -156,7 +156,7 @@ class RemoteBIGSdbMLSTProfiler(BIGSdbMLSTProfiler): if len(names_list) > 0: result_mlst_profile = NamedMLSTProfile(str(tuple(names_list)) if len(set(names_list)) > 1 else names_list[0], result_mlst_profile) return result_mlst_profile - except (ConnectionError, ServerDisconnectedError) as e: + except (ConnectionError, ServerDisconnectedError, ClientOSError) as e: last_error = e success = False await asyncio.sleep(5) @@ -165,7 +165,7 @@ class RemoteBIGSdbMLSTProfiler(BIGSdbMLSTProfiler): try: if last_error is not None: raise last_error - except (ConnectionError, ServerDisconnectedError) as e: + except (ConnectionError, ServerDisconnectedError, ClientOSError) as e: result_mlst_profile = NamedMLSTProfile((str(tuple(names_list)) if len(set(names_list)) > 1 else names_list[0]) + ":Error", None) raise ValueError("Last error was not recorded.")