Skip to content

Commit

Permalink
Define all DBAPI required errors in prestodb.exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
takuti authored and ggreg committed Feb 7, 2019
1 parent 1262f1b commit f0efe0e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
20 changes: 2 additions & 18 deletions prestodb/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,6 @@
logger = prestodb.logging.get_logger(__name__)


class Error(Exception):
pass


class OperationalError(Error):
"""
Exception raised for errors that are related to the database's operation
and not necessarily under the control of the programmer, e.g. an unexpected
disconnect occurs, the data source name is not found, a transaction could
not be processed, a memory allocation error occurred during processing, ...
"""
pass


def connect(*args, **kwargs):
"""Constructor for creating a connection to the database.
Expand Down Expand Up @@ -266,7 +250,7 @@ def fetchone(self):
except StopIteration:
return None
except prestodb.exceptions.HttpError as err:
raise OperationalError(str(err))
raise prestodb.exceptions.OperationalError(str(err))

def fetchmany(self, size=None):
# type: (Optional[int]) -> List[List[Any]]
Expand Down Expand Up @@ -311,7 +295,7 @@ def fetchall(self):

def cancel(self):
if self._query is None:
raise OperationalError("Cancel query failed; no running query")
raise prestodb.exceptions.OperationalError("Cancel query failed; no running query")
self._query.cancel()

def close(self):
Expand Down
45 changes: 41 additions & 4 deletions prestodb/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ class PrestoError(Exception):
pass


class DatabaseError(Exception):
pass


class TimeoutError(Exception):
pass

Expand Down Expand Up @@ -176,3 +172,44 @@ def __init__(
def retry(self, func, args, kwargs, err, attempt):
delay = self._get_delay(attempt)
time.sleep(delay)


# PEP 249
class Error(Exception):
pass


class Warning(Exception):
pass


class InterfaceError(Error):
pass


class DatabaseError(Error):
pass


class InternalError(DatabaseError):
pass


class OperationalError(DatabaseError):
pass


class ProgrammingError(DatabaseError):
pass


class IntegrityError(DatabaseError):
pass


class DataError(DatabaseError):
pass


class NotSupportedError(DatabaseError):
pass

0 comments on commit f0efe0e

Please sign in to comment.