From 2bc13de89194883c1412881d76759150ae58f5f4 Mon Sep 17 00:00:00 2001 From: James Stevenson Date: Thu, 14 Dec 2023 09:32:57 -0500 Subject: [PATCH] change exception names --- docs/source/api/etl_api.rst | 7 ------ docs/source/api/query_api.rst | 6 ----- src/gene/cli.py | 6 ++--- src/gene/database/__init__.py | 8 +++---- src/gene/database/database.py | 32 ++++++++++++------------- src/gene/database/dynamodb.py | 42 ++++++++++++++++----------------- src/gene/database/postgresql.py | 42 ++++++++++++++++----------------- src/gene/etl/__init__.py | 15 ++---------- src/gene/etl/base.py | 4 ++++ src/gene/etl/ensembl.py | 5 +--- src/gene/etl/exceptions.py | 15 ------------ src/gene/etl/hgnc.py | 5 +--- src/gene/etl/merge.py | 6 ++--- src/gene/etl/ncbi.py | 5 +--- src/gene/etl/update.py | 9 ++++--- src/gene/query.py | 18 ++++---------- 16 files changed, 85 insertions(+), 140 deletions(-) delete mode 100644 src/gene/etl/exceptions.py diff --git a/docs/source/api/etl_api.rst b/docs/source/api/etl_api.rst index 4410e3d9..26a58c8e 100644 --- a/docs/source/api/etl_api.rst +++ b/docs/source/api/etl_api.rst @@ -9,13 +9,6 @@ Update methods .. automodule:: gene.etl.update :members: -Exceptions ----------- - -.. automodule:: gene.etl.exceptions - :members: - :show-inheritance: - NCBI ---- diff --git a/docs/source/api/query_api.rst b/docs/source/api/query_api.rst index 438fa908..9aac7694 100644 --- a/docs/source/api/query_api.rst +++ b/docs/source/api/query_api.rst @@ -7,9 +7,3 @@ Query API :members: :special-members: __init__ :undoc-members: - -.. autoexception:: gene.query.InvalidParameterException - :members: - :undoc-members: - :show-inheritance: - diff --git a/src/gene/cli.py b/src/gene/cli.py index fc4e168c..314411fe 100644 --- a/src/gene/cli.py +++ b/src/gene/cli.py @@ -7,7 +7,7 @@ import click from gene.database import create_db -from gene.database.database import DatabaseException +from gene.database.database import DatabaseError from gene.etl.update import update_all_sources, update_normalized, update_source from gene.schemas import SourceName @@ -142,7 +142,7 @@ def update_from_remote(data_url: Optional[str], db_url: str, silent: bool) -> No f"Error: Fetching remote data dump not supported for {db.__class__.__name__}" ) # noqa: E501 click.get_current_context().exit(1) - except DatabaseException as e: + except DatabaseError as e: click.echo(f"Encountered exception during update: {str(e)}") click.get_current_context().exit(1) @@ -225,7 +225,7 @@ def dump_database(output_directory: Path, db_url: str, silent: bool) -> None: f"Error: Dumping data to file not supported for {db.__class__.__name__}" ) # noqa: E501 click.get_current_context().exit(1) - except DatabaseException as e: + except DatabaseError as e: click.echo(f"Encountered exception during update: {str(e)}") click.get_current_context().exit(1) diff --git a/src/gene/database/__init__.py b/src/gene/database/__init__.py index 3a71e721..b131c435 100644 --- a/src/gene/database/__init__.py +++ b/src/gene/database/__init__.py @@ -2,9 +2,9 @@ from .database import ( AWS_ENV_VAR_NAME, AbstractDatabase, - DatabaseException, - DatabaseInitializationException, - DatabaseReadException, - DatabaseWriteException, + DatabaseError, + DatabaseInitializationError, + DatabaseReadError, + DatabaseWriteError, create_db, ) diff --git a/src/gene/database/database.py b/src/gene/database/database.py index 76cb7acc..bfe4179a 100644 --- a/src/gene/database/database.py +++ b/src/gene/database/database.py @@ -11,19 +11,19 @@ from gene.schemas import RecordType, RefType, SourceMeta, SourceName -class DatabaseException(Exception): # noqa: N818 +class DatabaseError(Exception): """Create custom class for handling database exceptions""" -class DatabaseInitializationException(DatabaseException): +class DatabaseInitializationError(DatabaseError): """Create custom exception for errors during DB connection initialization.""" -class DatabaseReadException(DatabaseException): +class DatabaseReadError(DatabaseError): """Create custom exception for lookup/read errors""" -class DatabaseWriteException(DatabaseException): +class DatabaseWriteError(DatabaseError): """Create custom exception for write errors""" @@ -43,7 +43,7 @@ def __init__(self, db_url: Optional[str] = None, **db_args) -> None: :param db_url: address/connection description for database :param db_args: any DB implementation-specific parameters - :raise DatabaseInitializationException: if initial setup fails + :raise DatabaseInitializationError: if initial setup fails """ @abc.abstractmethod @@ -58,12 +58,12 @@ def _check_delete_okay() -> bool: """Check that environmental conditions permit DB deletion, and require confirmation. - :raise DatabaseWriteException: if skip confirmation variable is set -- manual + :raise DatabaseWriteError: if skip confirmation variable is set -- manual approval is required. """ if environ.get(AWS_ENV_VAR_NAME, "") == AwsEnvName.PRODUCTION: if environ.get(SKIP_AWS_DB_ENV_NAME, "") == "true": - raise DatabaseWriteException( + raise DatabaseWriteError( f"Must unset {SKIP_AWS_DB_ENV_NAME} env variable to enable drop_db()" # noqa: E501 ) return click.confirm("Are you sure you want to delete existing data?") @@ -75,8 +75,8 @@ def drop_db(self) -> None: """Initiate total teardown of DB. Useful for quickly resetting the entirety of the data. Requires manual confirmation. - :raise DatabaseWriteException: if called in a protected setting with - confirmation silenced. + :raise DatabaseWriteError: if called in a protected setting with confirmation + silenced. """ @abc.abstractmethod @@ -103,7 +103,7 @@ def initialize_db(self) -> None: existing content -- ie, this method is also responsible for checking whether the DB is already set up. - :raise DatabaseInitializationException: if initialization fails + :raise DatabaseInitializationError: if initialization fails """ @abc.abstractmethod @@ -168,7 +168,7 @@ def add_source_metadata(self, src_name: SourceName, data: SourceMeta) -> None: :param src_name: name of source :param data: known source attributes - :raise DatabaseWriteException: if write fails + :raise DatabaseWriteError: if write fails """ @abc.abstractmethod @@ -192,7 +192,7 @@ def update_merge_ref(self, concept_id: str, merge_ref: Any) -> None: # noqa: AN :param concept_id: record to update :param merge_ref: new ref value - :raise DatabaseWriteException: if attempting to update non-existent record + :raise DatabaseWriteError: if attempting to update non-existent record """ @abc.abstractmethod @@ -200,9 +200,9 @@ def delete_normalized_concepts(self) -> None: """Remove merged records from the database. Use when performing a new update of normalized data. - :raise DatabaseReadException: if DB client requires separate read calls and + :raise DatabaseReadError: if DB client requires separate read calls and encounters a failure in the process - :raise DatabaseWriteException: if deletion call fails + :raise DatabaseWriteError: if deletion call fails """ @abc.abstractmethod @@ -210,9 +210,9 @@ def delete_source(self, src_name: SourceName) -> None: """Delete all data for a source. Use when updating source data. :param src_name: name of source to delete - :raise DatabaseReadException: if DB client requires separate read calls and + :raise DatabaseReadError: if DB client requires separate read calls and encounters a failure in the process - :raise DatabaseWriteException: if deletion call fails + :raise DatabaseWriteError: if deletion call fails """ @abc.abstractmethod diff --git a/src/gene/database/dynamodb.py b/src/gene/database/dynamodb.py index e33c98ec..2ab6b1d2 100644 --- a/src/gene/database/dynamodb.py +++ b/src/gene/database/dynamodb.py @@ -17,9 +17,9 @@ VALID_AWS_ENV_NAMES, AbstractDatabase, AwsEnvName, - DatabaseInitializationException, - DatabaseReadException, - DatabaseWriteException, + DatabaseInitializationError, + DatabaseReadError, + DatabaseWriteError, confirm_aws_db_use, ) from gene.schemas import ( @@ -44,20 +44,20 @@ def __init__(self, db_url: Optional[str] = None, **db_args) -> None: :Keyword Arguments: * region_name: AWS region (defaults to "us-east-2") * silent: if True, suppress console output - :raise DatabaseInitializationException: if initial setup fails + :raise DatabaseInitializationError: if initial setup fails """ self.gene_table = environ.get("GENE_DYNAMO_TABLE", "gene_normalizer") region_name = db_args.get("region_name", "us-east-2") if AWS_ENV_VAR_NAME in environ: if "GENE_TEST" in environ: - raise DatabaseInitializationException( + raise DatabaseInitializationError( f"Cannot have both GENE_TEST and {AWS_ENV_VAR_NAME} set." ) # noqa: E501 try: aws_env = AwsEnvName(environ[AWS_ENV_VAR_NAME]) except ValueError: - raise DatabaseInitializationException( + raise DatabaseInitializationError( f"{AWS_ENV_VAR_NAME} must be one of {VALID_AWS_ENV_NAMES}: found {environ[AWS_ENV_VAR_NAME]} instead." ) skip_confirmation = environ.get(SKIP_AWS_DB_ENV_NAME) @@ -108,13 +108,13 @@ def list_tables(self) -> List[str]: def drop_db(self) -> None: """Delete all tables from database. Requires manual confirmation. - :raise DatabaseWriteException: if called in a protected setting with - confirmation silenced. + :raise DatabaseWriteError: if called in a protected setting with confirmation + silenced. """ try: if not self._check_delete_okay(): return - except DatabaseWriteException as e: + except DatabaseWriteError as e: raise e if self.gene_table in self.list_tables(): @@ -226,7 +226,7 @@ def get_source_metadata(self, src_name: Union[str, SourceName]) -> Dict: Key={"label_and_type": pk, "concept_id": concept_id} ).get("Item") if not metadata: - raise DatabaseReadException( + raise DatabaseReadError( f"Unable to retrieve data for source {src_name}" ) self._cached_sources[src_name] = metadata @@ -362,7 +362,7 @@ def add_source_metadata(self, src_name: SourceName, metadata: SourceMeta) -> Non :param src_name: name of source :param data: known source attributes - :raise DatabaseWriteException: if write fails + :raise DatabaseWriteError: if write fails """ src_name_value = src_name.value metadata_item = metadata.model_dump() @@ -373,7 +373,7 @@ def add_source_metadata(self, src_name: SourceName, metadata: SourceMeta) -> Non try: self.genes.put_item(Item=metadata_item) except ClientError as e: - raise DatabaseWriteException(e) + raise DatabaseWriteError(e) def add_record(self, record: Dict, src_name: SourceName) -> None: """Add new record to database. @@ -458,7 +458,7 @@ def update_merge_ref(self, concept_id: str, merge_ref: Any) -> None: # noqa: AN :param concept_id: record to update :param merge_ref: new ref value - :raise DatabaseWriteException: if attempting to update non-existent record + :raise DatabaseWriteError: if attempting to update non-existent record """ label_and_type = f"{concept_id.lower()}##identity" key = {"label_and_type": label_and_type, "concept_id": concept_id} @@ -475,7 +475,7 @@ def update_merge_ref(self, concept_id: str, merge_ref: Any) -> None: # noqa: AN except ClientError as e: code = e.response.get("Error", {}).get("Code") if code == "ConditionalCheckFailedException": - raise DatabaseWriteException( + raise DatabaseWriteError( f"No such record exists for keys {label_and_type}, {concept_id}" ) else: @@ -488,9 +488,9 @@ def delete_normalized_concepts(self) -> None: """Remove merged records from the database. Use when performing a new update of normalized data. - :raise DatabaseReadException: if DB client requires separate read calls and + :raise DatabaseReadError: if DB client requires separate read calls and encounters a failure in the process - :raise DatabaseWriteException: if deletion call fails + :raise DatabaseWriteError: if deletion call fails """ while True: with self.genes.batch_writer( @@ -504,7 +504,7 @@ def delete_normalized_concepts(self) -> None: ), ) except ClientError as e: - raise DatabaseReadException(e) + raise DatabaseReadError(e) records = response["Items"] if not records: break @@ -520,9 +520,9 @@ def delete_source(self, src_name: SourceName) -> None: """Delete all data for a source. Use when updating source data. :param src_name: name of source to delete - :raise DatabaseReadException: if DB client requires separate read calls and + :raise DatabaseReadError: if DB client requires separate read calls and encounters a failure in the process - :raise DatabaseWriteException: if deletion call fails + :raise DatabaseWriteError: if deletion call fails """ while True: try: @@ -531,7 +531,7 @@ def delete_source(self, src_name: SourceName) -> None: KeyConditionExpression=Key("src_name").eq(src_name.value), ) except ClientError as e: - raise DatabaseReadException(e) + raise DatabaseReadError(e) records = response["Items"] if not records: break @@ -547,7 +547,7 @@ def delete_source(self, src_name: SourceName) -> None: } ) except ClientError as e: - raise DatabaseWriteException(e) + raise DatabaseWriteError(e) def complete_write_transaction(self) -> None: """Conclude transaction or batch writing if relevant.""" diff --git a/src/gene/database/postgresql.py b/src/gene/database/postgresql.py index 82149cb9..59b992ff 100644 --- a/src/gene/database/postgresql.py +++ b/src/gene/database/postgresql.py @@ -21,9 +21,9 @@ from gene.database import ( AbstractDatabase, - DatabaseException, - DatabaseReadException, - DatabaseWriteException, + DatabaseError, + DatabaseReadError, + DatabaseWriteError, ) from gene.schemas import RecordType, RefType, SourceMeta, SourceName @@ -54,7 +54,7 @@ def __init__(self, db_url: Optional[str] = None, **db_args) -> None: * db_name: name of database to connect to * silent: if True, suppress console output - :raise DatabaseInitializationException: if initial setup fails + :raise DatabaseInitializationError: if initial setup fails """ if db_url: conninfo = db_url @@ -112,13 +112,13 @@ def drop_db(self) -> None: reconstructing after apparent schema error. If in a protected environment, require confirmation. - :raise DatabaseWriteException: if called in a protected setting with - confirmation silenced. + :raise DatabaseWriteError: if called in a protected setting with confirmation + silenced. """ try: if not self._check_delete_okay(): return - except DatabaseWriteException as e: + except DatabaseWriteError as e: raise e with self.conn.cursor() as cur: @@ -288,7 +288,7 @@ def get_source_metadata(self, src_name: SourceName) -> Dict: cur.execute(metadata_query, [src_name]) metadata_result = cur.fetchone() if not metadata_result: - raise DatabaseReadException(f"{src_name} metadata lookup failed") + raise DatabaseReadError(f"{src_name} metadata lookup failed") metadata = { "data_license": metadata_result[1], "data_license_url": metadata_result[2], @@ -523,7 +523,7 @@ def add_source_metadata(self, src_name: SourceName, meta: SourceMeta) -> None: :param src_name: name of source :param meta: known source attributes - :raise DatabaseWriteException: if write fails + :raise DatabaseWriteError: if write fails """ with self.conn.cursor() as cur: cur.execute( @@ -661,7 +661,7 @@ def update_merge_ref(self, concept_id: str, merge_ref: Any) -> None: # noqa: AN :param concept_id: record to update :param merge_ref: new ref value - :raise DatabaseWriteException: if attempting to update non-existent record + :raise DatabaseWriteError: if attempting to update non-existent record """ with self.conn.cursor() as cur: cur.execute( @@ -673,7 +673,7 @@ def update_merge_ref(self, concept_id: str, merge_ref: Any) -> None: # noqa: AN # UPDATE will fail silently unless we check the # of affected rows if row_count < 1: - raise DatabaseWriteException( + raise DatabaseWriteError( f"No such record exists for primary key {concept_id}" ) @@ -687,9 +687,9 @@ def delete_normalized_concepts(self) -> None: accessing it, or PgAdmin, etc...). Instead, we'll take down each part of the merge_ref - :raise DatabaseReadException: if DB client requires separate read calls and + :raise DatabaseReadError: if DB client requires separate read calls and encounters a failure in the process - :raise DatabaseWriteException: if deletion call fails + :raise DatabaseWriteError: if deletion call fails """ with self.conn.cursor() as cur: cur.execute((SCRIPTS_DIR / "delete_normalized_concepts.sql").read_bytes()) @@ -746,7 +746,7 @@ def delete_source(self, src_name: SourceName) -> None: but it's probably necessary just in case that doesn't happen. :param src_name: name of source to delete - :raise DatabaseWriteException: if deletion call fails + :raise DatabaseWriteError: if deletion call fails """ with self.conn.cursor() as cur: cur.execute(self._drop_aliases_query, [src_name.value]) @@ -785,8 +785,8 @@ def load_from_remote(self, url: Optional[str]) -> None: passed as an argument, will try to grab latest release from VICC S3 bucket. :param url: location of .tar.gz file created from output of pg_dump - :raise DatabaseException: if unable to retrieve file from URL or if psql - command fails + :raise DatabaseError: if unable to retrieve file from URL or if psql command + fails """ if not url: url = "https://vicc-normalizers.s3.us-east-2.amazonaws.com/gene_normalization/postgresql/gene_norm_latest.sql.tar.gz" # noqa: E501 @@ -797,7 +797,7 @@ def load_from_remote(self, url: Optional[str]) -> None: try: r.raise_for_status() except requests.HTTPError: - raise DatabaseException( + raise DatabaseError( f"Unable to retrieve PostgreSQL dump file from {url}" ) with open(temp_tarfile, "wb") as h: @@ -820,9 +820,7 @@ def load_from_remote(self, url: Optional[str]) -> None: system_call = f"psql -d {self.conn.info.dbname} -U {self.conn.info.user} {pw_param} -f {dump_file.absolute()}" # noqa: E501 result = os.system(system_call) if result != 0: - raise DatabaseException( - f"System call '{result}' returned failing exit code." - ) + raise DatabaseError(f"System call '{result}' returned failing exit code.") def export_db(self, output_directory: Path) -> None: """Dump DB to specified location. @@ -831,7 +829,7 @@ def export_db(self, output_directory: Path) -> None: :return: Nothing, but saves results of pg_dump to file named `gene_norm_.sql` :raise ValueError: if output directory isn't a directory or doesn't exist - :raise DatabaseException: if psql call fails + :raise DatabaseError: if psql call fails """ if not output_directory.is_dir() or not output_directory.exists(): raise ValueError( @@ -851,6 +849,6 @@ def export_db(self, output_directory: Path) -> None: system_call = f"pg_dump -E UTF8 -f {output_location} -U {user} {pw_param} -h {host} -p {port} {database_name}" # noqa: E501 result = os.system(system_call) if result != 0: - raise DatabaseException( + raise DatabaseError( f"System call '{system_call}' returned failing exit code." ) diff --git a/src/gene/etl/__init__.py b/src/gene/etl/__init__.py index 569df1d7..867e0f75 100644 --- a/src/gene/etl/__init__.py +++ b/src/gene/etl/__init__.py @@ -1,18 +1,7 @@ """Module to load and init namespace at package level.""" +from .base import GeneNormalizerEtlError from .ensembl import Ensembl -from .exceptions import ( - GeneFileVersionError, - GeneNormalizerEtlError, - GeneSourceFetchError, -) from .hgnc import HGNC from .ncbi import NCBI -__all__ = [ - "Ensembl", - "HGNC", - "NCBI", - "GeneNormalizerEtlError", - "GeneFileVersionError", - "GeneSourceFetchError", -] +__all__ = ["Ensembl", "HGNC", "NCBI", "GeneNormalizerEtlError"] diff --git a/src/gene/etl/base.py b/src/gene/etl/base.py index f06c89a0..1b23d93c 100644 --- a/src/gene/etl/base.py +++ b/src/gene/etl/base.py @@ -19,6 +19,10 @@ logger.setLevel(logging.DEBUG) +class GeneNormalizerEtlError(Exception): + """Basic ETL exception.""" + + APP_ROOT = Path(__file__).resolve().parent SEQREPO_ROOT_DIR = Path( environ.get("SEQREPO_ROOT_DIR", "/usr/local/share/seqrepo/latest") diff --git a/src/gene/etl/ensembl.py b/src/gene/etl/ensembl.py index 4a52975a..bab569e7 100644 --- a/src/gene/etl/ensembl.py +++ b/src/gene/etl/ensembl.py @@ -6,10 +6,7 @@ import gffutils from gffutils.feature import Feature -from gene.etl.base import Base -from gene.etl.exceptions import ( - GeneNormalizerEtlError, -) +from gene.etl.base import Base, GeneNormalizerEtlError from gene.schemas import NamespacePrefix, SourceMeta, SourceName, Strand logger = logging.getLogger("gene") diff --git a/src/gene/etl/exceptions.py b/src/gene/etl/exceptions.py deleted file mode 100644 index 43ce6ad1..00000000 --- a/src/gene/etl/exceptions.py +++ /dev/null @@ -1,15 +0,0 @@ -"""Provide ETL-specific exceptions.""" - - -class GeneNormalizerEtlError(Exception): - """Base ETL exception.""" - - -class GeneFileVersionError(GeneNormalizerEtlError): - """Raise when unable to parse version number from saved data file.""" - - -class GeneSourceFetchError(GeneNormalizerEtlError): - """Raise during data acquisition when data fetch fails (e.g. unable to get latest - version number, or connection failure during download) - """ diff --git a/src/gene/etl/hgnc.py b/src/gene/etl/hgnc.py index 9e4c048e..4d015d1f 100644 --- a/src/gene/etl/hgnc.py +++ b/src/gene/etl/hgnc.py @@ -4,10 +4,7 @@ import re from typing import Dict -from gene.etl.base import Base -from gene.etl.exceptions import ( - GeneNormalizerEtlError, -) +from gene.etl.base import Base, GeneNormalizerEtlError from gene.schemas import ( PREFIX_LOOKUP, Annotation, diff --git a/src/gene/etl/merge.py b/src/gene/etl/merge.py index 8124d294..4939d229 100644 --- a/src/gene/etl/merge.py +++ b/src/gene/etl/merge.py @@ -4,7 +4,7 @@ from typing import Dict, Optional, Set, Tuple from gene.database import AbstractDatabase -from gene.database.database import DatabaseWriteException +from gene.database.database import DatabaseWriteError from gene.schemas import GeneTypeFieldName, RecordType, SourcePriority logger = logging.getLogger("gene") @@ -56,7 +56,7 @@ def create_merged_concepts(self, record_ids: Set[str]) -> None: merge_ref = merged_record["concept_id"] try: self._database.update_merge_ref(concept_id, merge_ref) - except DatabaseWriteException as dw: + except DatabaseWriteError as dw: if str(dw).startswith("No such record exists"): logger.error( f"Updating nonexistent record: {concept_id} " @@ -135,7 +135,7 @@ def record_order(record: Dict) -> Tuple: if src in SourcePriority.__members__: source_rank = SourcePriority[src].value else: - raise Exception( + raise ValueError( f"Prohibited source: {src} in concept_id " f"{record['concept_id']}" ) return source_rank, record["concept_id"] diff --git a/src/gene/etl/ncbi.py b/src/gene/etl/ncbi.py index a136c4b2..c7ae66d9 100644 --- a/src/gene/etl/ncbi.py +++ b/src/gene/etl/ncbi.py @@ -10,10 +10,7 @@ from wags_tails.ncbi import NcbiGenePaths from gene.database import AbstractDatabase -from gene.etl.base import SEQREPO_ROOT_DIR, Base -from gene.etl.exceptions import ( - GeneNormalizerEtlError, -) +from gene.etl.base import SEQREPO_ROOT_DIR, Base, GeneNormalizerEtlError from gene.schemas import ( PREFIX_LOOKUP, Annotation, diff --git a/src/gene/etl/update.py b/src/gene/etl/update.py index 489ccd70..25cf98ed 100644 --- a/src/gene/etl/update.py +++ b/src/gene/etl/update.py @@ -7,8 +7,8 @@ from gene.database.database import ( AbstractDatabase, - DatabaseReadException, - DatabaseWriteException, + DatabaseReadError, + DatabaseWriteError, ) from gene.schemas import SourceName @@ -62,8 +62,7 @@ def load_source( # used to get source class name from string try: - from gene.etl import HGNC, NCBI, Ensembl # noqa: F401 - from gene.etl.exceptions import GeneNormalizerEtlError + from gene.etl import HGNC, NCBI, Ensembl, GeneNormalizerEtlError # noqa: F401 except ModuleNotFoundError as e: click.echo( f"Encountered ModuleNotFoundError attempting to import {e.name}. {_etl_dependency_help}" @@ -150,7 +149,7 @@ def delete_normalized(database: AbstractDatabase, silent: bool = True) -> None: start_delete = timer() try: database.delete_normalized_concepts() - except (DatabaseReadException, DatabaseWriteException) as e: + except (DatabaseReadError, DatabaseWriteError) as e: click.echo(f"Encountered exception during normalized data deletion: {e}") raise e end_delete = timer() diff --git a/src/gene/query.py b/src/gene/query.py index d402390d..8c100446 100644 --- a/src/gene/query.py +++ b/src/gene/query.py @@ -7,7 +7,7 @@ from ga4gh.core import core_models, ga4gh_identify from ga4gh.vrs import models -from gene.database import AbstractDatabase, DatabaseReadException +from gene.database import AbstractDatabase, DatabaseReadError from gene.schemas import ( ITEM_TYPES, NAMESPACE_LOOKUP, @@ -35,10 +35,6 @@ NormService = TypeVar("NormService", bound=BaseNormalizationService) -class InvalidParameterException(Exception): # noqa: N818 - """Exception for invalid parameter args provided by the user.""" - - class QueryHandler: """Class for normalizer management. Stores reference to database instance and normalizes query input. @@ -191,10 +187,8 @@ def _fetch_record( """ try: match = self.db.get_record_by_id(concept_id, case_sensitive=False) - except DatabaseReadException as e: - _logger.error( - f"Encountered DatabaseReadException looking up {concept_id}: {e}" - ) + except DatabaseReadError as e: + _logger.error(f"Encountered DatabaseReadError looking up {concept_id}: {e}") else: if match: self._add_record(response, match, match_type) @@ -266,9 +260,9 @@ def _get_search_response(self, query: str, sources: Iterable[SourceName]) -> Dic self._fetch_record(resp, ref, MatchType[item_type.upper()]) matched_concept_ids.append(ref) - except DatabaseReadException as e: + except DatabaseReadError as e: _logger.error( - f"Encountered DatabaseReadException looking up {item_type}" + f"Encountered DatabaseReadError looking up {item_type}" f" {term}: {e}" ) continue @@ -301,8 +295,6 @@ def search( :param query_str: query, a string, to search for :param sources: If given, only return records from these sources :return: SearchService class containing all matches found in sources. - :raise InvalidParameterException: if both `incl` and `excl` args are provided, - or if invalid source names are given """ if not sources: sources = list(SourceName.__members__.values())