Skip to content

Commit f0efe0e

Browse files
takutiggreg
authored andcommitted
Define all DBAPI required errors in prestodb.exceptions
1 parent 1262f1b commit f0efe0e

File tree

2 files changed

+43
-22
lines changed

2 files changed

+43
-22
lines changed

prestodb/dbapi.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,6 @@
4040
logger = prestodb.logging.get_logger(__name__)
4141

4242

43-
class Error(Exception):
44-
pass
45-
46-
47-
class OperationalError(Error):
48-
"""
49-
50-
Exception raised for errors that are related to the database's operation
51-
and not necessarily under the control of the programmer, e.g. an unexpected
52-
disconnect occurs, the data source name is not found, a transaction could
53-
not be processed, a memory allocation error occurred during processing, ...
54-
55-
"""
56-
pass
57-
58-
5943
def connect(*args, **kwargs):
6044
"""Constructor for creating a connection to the database.
6145
@@ -266,7 +250,7 @@ def fetchone(self):
266250
except StopIteration:
267251
return None
268252
except prestodb.exceptions.HttpError as err:
269-
raise OperationalError(str(err))
253+
raise prestodb.exceptions.OperationalError(str(err))
270254

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

312296
def cancel(self):
313297
if self._query is None:
314-
raise OperationalError("Cancel query failed; no running query")
298+
raise prestodb.exceptions.OperationalError("Cancel query failed; no running query")
315299
self._query.cancel()
316300

317301
def close(self):

prestodb/exceptions.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ class PrestoError(Exception):
4040
pass
4141

4242

43-
class DatabaseError(Exception):
44-
pass
45-
46-
4743
class TimeoutError(Exception):
4844
pass
4945

@@ -176,3 +172,44 @@ def __init__(
176172
def retry(self, func, args, kwargs, err, attempt):
177173
delay = self._get_delay(attempt)
178174
time.sleep(delay)
175+
176+
177+
# PEP 249
178+
class Error(Exception):
179+
pass
180+
181+
182+
class Warning(Exception):
183+
pass
184+
185+
186+
class InterfaceError(Error):
187+
pass
188+
189+
190+
class DatabaseError(Error):
191+
pass
192+
193+
194+
class InternalError(DatabaseError):
195+
pass
196+
197+
198+
class OperationalError(DatabaseError):
199+
pass
200+
201+
202+
class ProgrammingError(DatabaseError):
203+
pass
204+
205+
206+
class IntegrityError(DatabaseError):
207+
pass
208+
209+
210+
class DataError(DatabaseError):
211+
pass
212+
213+
214+
class NotSupportedError(DatabaseError):
215+
pass

0 commit comments

Comments
 (0)