Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_nonexistant_table_raises(self, nonexistant_table):
result = _translate_exception(nonexistant_table)
assert isinstance(result, DatabaseError)
assert "Exception occurred: Table" in result.args[0]
class IntegrityError(DatabaseError):
"""Raised when the relational integrity of the database is affected."""
class InternalError(DatabaseError):
"""Raised for errors internal to the database, e.g. and invalid cursor."""
class ProgrammingError(DatabaseError):
"""Raised for programming errors, e.g. syntax errors, table already
exists.
"""
class NotSupportedError(DatabaseError):
"""Raised when an API not supported by the database is used."""
def _translate_exception(e):
# type: (Exception) -> Exception
"""Translate a thrift-land exception to a DB-API 2.0
exception.
"""
# TODO: see if there's a way to get error codes, rather than relying msgs
if not isinstance(e, TMapDException):
return e
if 'Validate failed' in e.error_msg or 'Parse failed' in e.error_msg:
err = ProgrammingError
elif 'Exception occurred' in e.error_msg:
err = DatabaseError
else:
"""Base class for all pymapd errors."""
class InterfaceError(Error):
"""Raised whenever you use pymapd interface incorrectly."""
class DatabaseError(Error):
"""Raised when the database encounters an error."""
class DataError(DatabaseError):
"""Raised for data processing errors like division by zero, etc."""
class OperationalError(DatabaseError):
"""Raised for non-programmer related database errors, e.g.
an unexpected disconnect.
"""
class IntegrityError(DatabaseError):
"""Raised when the relational integrity of the database is affected."""
class InternalError(DatabaseError):
"""Raised for errors internal to the database, e.g. and invalid cursor."""
class ProgrammingError(DatabaseError):
"""Raised for programming errors, e.g. syntax errors, table already
exists.
class OperationalError(DatabaseError):
"""Raised for non-programmer related database errors, e.g.
an unexpected disconnect.
"""
class IntegrityError(DatabaseError):
"""Raised when the relational integrity of the database is affected."""
class InternalError(DatabaseError):
"""Raised for errors internal to the database, e.g. and invalid cursor."""
class ProgrammingError(DatabaseError):
"""Raised for programming errors, e.g. syntax errors, table already
exists.
"""
class NotSupportedError(DatabaseError):
"""Raised when an API not supported by the database is used."""
def _translate_exception(e):
# type: (Exception) -> Exception
"""Translate a thrift-land exception to a DB-API 2.0
exception.
"""
# TODO: see if there's a way to get error codes, rather than relying msgs
if not isinstance(e, TMapDException):
"""Emitted for important warnings, e.g. data truncatiions"""
class Error(Exception):
"""Base class for all pymapd errors."""
class InterfaceError(Error):
"""Raised whenever you use pymapd interface incorrectly."""
class DatabaseError(Error):
"""Raised when the database encounters an error."""
class DataError(DatabaseError):
"""Raised for data processing errors like division by zero, etc."""
class OperationalError(DatabaseError):
"""Raised for non-programmer related database errors, e.g.
an unexpected disconnect.
"""
class IntegrityError(DatabaseError):
"""Raised when the relational integrity of the database is affected."""
class InternalError(DatabaseError):
"""Raised for errors internal to the database, e.g. and invalid cursor."""
class DataError(DatabaseError):
"""Raised for data processing errors like division by zero, etc."""
class OperationalError(DatabaseError):
"""Raised for non-programmer related database errors, e.g.
an unexpected disconnect.
"""
class IntegrityError(DatabaseError):
"""Raised when the relational integrity of the database is affected."""
class InternalError(DatabaseError):
"""Raised for errors internal to the database, e.g. and invalid cursor."""
class ProgrammingError(DatabaseError):
"""Raised for programming errors, e.g. syntax errors, table already
exists.
"""
class NotSupportedError(DatabaseError):
"""Raised when an API not supported by the database is used."""
def _translate_exception(e):
# type: (Exception) -> Exception
"""Translate a thrift-land exception to a DB-API 2.0
class DatabaseError(Error):
"""Raised when the database encounters an error."""
class DataError(DatabaseError):
"""Raised for data processing errors like division by zero, etc."""
class OperationalError(DatabaseError):
"""Raised for non-programmer related database errors, e.g.
an unexpected disconnect.
"""
class IntegrityError(DatabaseError):
"""Raised when the relational integrity of the database is affected."""
class InternalError(DatabaseError):
"""Raised for errors internal to the database, e.g. and invalid cursor."""
class ProgrammingError(DatabaseError):
"""Raised for programming errors, e.g. syntax errors, table already
exists.
"""
class NotSupportedError(DatabaseError):
"""Raised when an API not supported by the database is used."""