Skip to content

Commit 748d197

Browse files
mdesmetebyhr
authored andcommitted
Convert dbapi errors into PEP 249 errors
1 parent 4e375c9 commit 748d197

File tree

1 file changed

+48
-50
lines changed

1 file changed

+48
-50
lines changed

trino/exceptions.py

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,57 @@
2121
logger = trino.logging.get_logger(__name__)
2222

2323

24-
class HttpError(Exception):
24+
# PEP 249 Errors
25+
class Error(Exception):
2526
pass
2627

2728

28-
class Http502Error(Exception):
29+
class Warning(Exception):
2930
pass
3031

3132

32-
class Http503Error(HttpError):
33+
class InterfaceError(Error):
3334
pass
3435

3536

36-
class Http504Error(HttpError):
37+
class DatabaseError(Error):
38+
pass
39+
40+
41+
class InternalError(DatabaseError):
42+
pass
43+
44+
45+
class OperationalError(DatabaseError):
46+
pass
47+
48+
49+
class ProgrammingError(DatabaseError):
50+
pass
51+
52+
53+
class IntegrityError(DatabaseError):
54+
pass
55+
56+
57+
class DataError(DatabaseError):
3758
pass
3859

3960

40-
class TrinoError(Exception):
61+
class NotSupportedError(DatabaseError):
4162
pass
4263

4364

44-
class TrinoAuthError(Exception):
65+
# dbapi module errors (extending PEP 249 errors)
66+
class TrinoAuthError(OperationalError):
4567
pass
4668

4769

48-
class TrinoDataError(Exception):
70+
class TrinoDataError(NotSupportedError):
4971
pass
5072

5173

52-
class TrinoQueryError(Exception):
74+
class TrinoQueryError(Error):
5375
def __init__(self, error, query_id=None):
5476
self._error = error
5577
self._query_id = query_id
@@ -100,70 +122,46 @@ def __str__(self):
100122
return repr(self)
101123

102124

103-
class TrinoExternalError(TrinoQueryError):
104-
pass
105-
106-
107-
class TrinoInternalError(TrinoQueryError):
108-
pass
109-
110-
111-
class TrinoUserError(TrinoQueryError):
112-
pass
113-
114-
115-
# PEP 249
116-
class Error(Exception):
125+
class TrinoExternalError(TrinoQueryError, OperationalError):
117126
pass
118127

119128

120-
class Warning(Exception):
129+
class TrinoInternalError(TrinoQueryError, InternalError):
121130
pass
122131

123132

124-
class InterfaceError(Error):
133+
class TrinoUserError(TrinoQueryError, ProgrammingError):
125134
pass
126135

127136

128-
class DatabaseError(Error):
129-
pass
130-
131-
132-
class InternalError(DatabaseError):
133-
pass
134-
135-
136-
class OperationalError(DatabaseError):
137-
pass
138-
139-
140-
class ProgrammingError(DatabaseError):
137+
class FailedToObtainAddedPrepareHeader(Error):
138+
"""
139+
Raise this exception when unable to find the 'X-Trino-Added-Prepare'
140+
header in the response of a PREPARE statement request.
141+
"""
141142
pass
142143

143144

144-
class IntegrityError(DatabaseError):
145+
class FailedToObtainDeallocatedPrepareHeader(Error):
146+
"""
147+
Raise this exception when unable to find the 'X-Trino-Deallocated-Prepare'
148+
header in the response of a DEALLOCATED statement request.
149+
"""
145150
pass
146151

147152

148-
class DataError(DatabaseError):
153+
# client module errors
154+
class HttpError(Exception):
149155
pass
150156

151157

152-
class NotSupportedError(DatabaseError):
158+
class Http502Error(HttpError):
153159
pass
154160

155161

156-
class FailedToObtainAddedPrepareHeader(Error):
157-
"""
158-
Raise this exception when unable to find the 'X-Trino-Added-Prepare'
159-
header in the response of a PREPARE statement request.
160-
"""
162+
class Http503Error(HttpError):
161163
pass
162164

163165

164-
class FailedToObtainDeallocatedPrepareHeader(Error):
165-
"""
166-
Raise this exception when unable to find the 'X-Trino-Deallocated-Prepare'
167-
header in the response of a DEALLOCATED statement request.
168-
"""
166+
class Http504Error(HttpError):
169167
pass

0 commit comments

Comments
 (0)