def convert_exceptions(msg: str) -> Iterator: """Convert internal boto exceptions to our InvalidDatabaseError""" import botocore.exceptions try: yield except botocore.exceptions.ClientError as exc: raise exceptions.InvalidDatabaseError(msg) from exc
def convert_exceptions(msg: str) -> Iterator: """Convert internal mysql exceptions to our InvalidDatabaseError""" from pymysql import OperationalError, InternalError, ProgrammingError try: yield except (OperationalError, InternalError, ProgrammingError) as exc: raise exceptions.InvalidDatabaseError(msg) from exc
def convert_exceptions(msg: str) -> Iterator: """Convert internal sqlite and boto exceptions to our InvalidDatabaseError""" import sqlite3 import botocore.exceptions try: yield except (sqlite3.OperationalError, botocore.exceptions.ClientError) as exc: raise exceptions.InvalidDatabaseError(msg) from exc
def convert_exceptions( error_message: str, exceptions_to_convert: ExceptionType = DATABASE_DRIVER_EXCEPTIONS_TO_CONVERT, ) -> Iterator: try: yield except exceptions_to_convert as exception: raise exceptions.InvalidDatabaseError(error_message) from exception
def _connection_callback(self) -> None: """Called after opening a new connection""" # check for version compatibility def versiontuple(version_string: str) -> Sequence[str]: return version_string.split('.') db_version = self.db_version current_version = __version__ if versiontuple(db_version)[:2] != versiontuple(current_version)[:2]: raise exceptions.InvalidDatabaseError( f'Version conflict: database was created in v{db_version}, ' f'but this is v{current_version}')
def _connection_callback(self) -> None: if not self.db_version_verified: # check for version compatibility def version_tuple(version_string: str) -> Sequence[str]: return version_string.split('.') db_version = self.db_version current_version = terracotta.__version__ if version_tuple(db_version)[:2] != version_tuple(current_version)[:2]: raise exceptions.InvalidDatabaseError( f'Version conflict: database was created in v{db_version}, ' f'but this is v{current_version}' ) self.db_version_verified = True
def convert_exceptions(msg: str) -> Iterator: """Convert internal sqlite exceptions to our InvalidDatabaseError""" try: yield except sqlite3.OperationalError as exc: raise exceptions.InvalidDatabaseError(msg) from exc