-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexceptions.py
More file actions
187 lines (158 loc) · 8.72 KB
/
exceptions.py
File metadata and controls
187 lines (158 loc) · 8.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# DBAPI 2.0 Exceptions Hierachy
#
# Exception
# |__Warning
# |__Error
# |__InterfaceError
# |__DatabaseError
# |__DataError
# |__OperationalError
# |__IntegrityError
# |__InternalError
# |__ProgrammingError
# |__NotSupportedError
class SQLiteCloudWarning(Exception):
def __init__(self, message: str, code: int = -1, xerrcode: int = 0) -> None:
super().__init__(message)
self.errmsg = f"Warning: {message}"
self.errcode = code
self.xerrcode = xerrcode
class SQLiteCloudError(Exception):
def __init__(self, message: str, code: int = -1, xerrcode: int = 0) -> None:
super().__init__(message)
self.errmsg = message
self.errcode = code
self.xerrcode = xerrcode
class SQLiteCloudInterfaceError(SQLiteCloudError):
def __init__(self, message: str, code: int = -1, xerrcode: int = 0) -> None:
super().__init__(message, code, xerrcode)
class SQLiteCloudDatabaseError(SQLiteCloudError):
def __init__(self, message: str, code: int = -1, xerrcode: int = 0) -> None:
super().__init__(message, code, xerrcode)
class SQLiteCloudDataError(SQLiteCloudDatabaseError):
def __init__(self, message: str, code: int = -1, xerrcode: int = 0) -> None:
super().__init__(message, code, xerrcode)
class SQLiteCloudOperationalError(SQLiteCloudDatabaseError):
def __init__(self, message: str, code: int = -1, xerrcode: int = 0) -> None:
super().__init__(message, code, xerrcode)
class SQLiteCloudIntegrityError(SQLiteCloudDatabaseError):
def __init__(self, message: str, code: int = -1, xerrcode: int = 0) -> None:
super().__init__(message, code, xerrcode)
class SQLiteCloudInternalError(SQLiteCloudDatabaseError):
def __init__(self, message: str, code: int = -1, xerrcode: int = 0) -> None:
super().__init__(message, code, xerrcode)
class SQLiteCloudProgrammingError(SQLiteCloudDatabaseError):
def __init__(self, message: str, code: int = -1, xerrcode: int = 0) -> None:
super().__init__(message, code, xerrcode)
class SQLiteCloudNotSupportedError(SQLiteCloudDatabaseError):
def __init__(self, message: str, code: int = -1, xerrcode: int = 0) -> None:
super().__init__(
f"The feature is not implemented in SQLite Cloud\n{message}", code, xerrcode
)
class SQLiteCloudException(SQLiteCloudError):
def __init__(self, message: str, code: int = -1, xerrcode: int = 0) -> None:
super().__init__(message, code, xerrcode)
def get_sqlitecloud_error_with_extended_code(
message: str, code: int, xerrcode: int
) -> None:
"""Mapping of sqlite error codes: https://www.sqlite.org/rescode.html"""
# define base error codes and their corresponding exceptions
base_error_mapping = {
1: SQLiteCloudOperationalError, # SQLITE_ERROR
2: SQLiteCloudInternalError, # SQLITE_INTERNAL
3: SQLiteCloudOperationalError, # SQLITE_PERM
4: SQLiteCloudOperationalError, # SQLITE_ABORT
5: SQLiteCloudOperationalError, # SQLITE_BUSY
6: SQLiteCloudOperationalError, # SQLITE_LOCKED
7: SQLiteCloudDatabaseError, # SQLITE_NOMEM
8: SQLiteCloudOperationalError, # SQLITE_READONLY
9: SQLiteCloudOperationalError, # SQLITE_INTERRUPT
10: SQLiteCloudOperationalError, # SQLITE_IOERR
11: SQLiteCloudDatabaseError, # SQLITE_CORRUPT
12: SQLiteCloudOperationalError, # SQLITE_NOTFOUND
13: SQLiteCloudOperationalError, # SQLITE_FULL
14: SQLiteCloudOperationalError, # SQLITE_CANTOPEN
15: SQLiteCloudOperationalError, # SQLITE_PROTOCOL
16: SQLiteCloudDatabaseError, # SQLITE_EMPTY
17: SQLiteCloudOperationalError, # SQLITE_SCHEMA
18: SQLiteCloudDataError, # SQLITE_TOOBIG
19: SQLiteCloudIntegrityError, # SQLITE_CONSTRAINT
20: SQLiteCloudProgrammingError, # SQLITE_MISMATCH
21: SQLiteCloudProgrammingError, # SQLITE_MISUSE
22: SQLiteCloudOperationalError, # SQLITE_NOLFS
23: SQLiteCloudOperationalError, # SQLITE_AUTH
24: SQLiteCloudDatabaseError, # SQLITE_FORMAT
25: SQLiteCloudDataError, # SQLITE_RANGE
26: SQLiteCloudDatabaseError, # SQLITE_NOTADB
27: SQLiteCloudWarning, # SQLITE_NOTICE
28: SQLiteCloudWarning, # SQLITE_WARNING
100: SQLiteCloudWarning, # SQLITE_ROW (not an error)
101: SQLiteCloudWarning, # SQLITE_DONE (not an error)
}
# define extended error codes and their corresponding exceptions
extended_error_mapping = {
257: SQLiteCloudOperationalError, # SQLITE_ERROR_MISSING_COLLSEQ
279: SQLiteCloudOperationalError, # SQLITE_AUTH_USER
266: SQLiteCloudOperationalError, # SQLITE_IOERR_READ
522: SQLiteCloudOperationalError, # SQLITE_IOERR_SHORT_READ
778: SQLiteCloudOperationalError, # SQLITE_IOERR_WRITE
1034: SQLiteCloudOperationalError, # SQLITE_IOERR_FSYNC
1290: SQLiteCloudOperationalError, # SQLITE_IOERR_DIR_FSYNC
1546: SQLiteCloudOperationalError, # SQLITE_IOERR_TRUNCATE
1802: SQLiteCloudOperationalError, # SQLITE_IOERR_FSTAT
2058: SQLiteCloudOperationalError, # SQLITE_IOERR_UNLOCK
2314: SQLiteCloudOperationalError, # SQLITE_IOERR_RDLOCK
2570: SQLiteCloudOperationalError, # SQLITE_IOERR_DELETE
2826: SQLiteCloudOperationalError, # SQLITE_IOERR_BLOCKED
3082: SQLiteCloudOperationalError, # SQLITE_IOERR_NOMEM
3338: SQLiteCloudOperationalError, # SQLITE_IOERR_ACCESS
3594: SQLiteCloudOperationalError, # SQLITE_IOERR_CHECKRESERVEDLOCK
3850: SQLiteCloudOperationalError, # SQLITE_IOERR_LOCK
4106: SQLiteCloudOperationalError, # SQLITE_IOERR_CLOSE
4362: SQLiteCloudOperationalError, # SQLITE_IOERR_DIR_CLOSE
4618: SQLiteCloudOperationalError, # SQLITE_IOERR_SHMOPEN
4874: SQLiteCloudOperationalError, # SQLITE_IOERR_SHMSIZE
5130: SQLiteCloudOperationalError, # SQLITE_IOERR_SHMLOCK
5386: SQLiteCloudOperationalError, # SQLITE_IOERR_SHMMAP
5642: SQLiteCloudOperationalError, # SQLITE_IOERR_SEEK
5898: SQLiteCloudOperationalError, # SQLITE_IOERR_DELETE_NOENT
6154: SQLiteCloudOperationalError, # SQLITE_IOERR_MMAP
6410: SQLiteCloudOperationalError, # SQLITE_IOERR_GETTEMPPATH
6666: SQLiteCloudOperationalError, # SQLITE_IOERR_CONVPATH
6922: SQLiteCloudOperationalError, # SQLITE_IOERR_VNODE
7178: SQLiteCloudOperationalError, # SQLITE_IOERR_AUTH
262: SQLiteCloudOperationalError, # SQLITE_LOCKED_SHAREDCACHE
261: SQLiteCloudOperationalError, # SQLITE_BUSY_RECOVERY
517: SQLiteCloudOperationalError, # SQLITE_BUSY_SNAPSHOT
270: SQLiteCloudOperationalError, # SQLITE_CANTOPEN_NOTEMPDIR
526: SQLiteCloudOperationalError, # SQLITE_CANTOPEN_ISDIR
782: SQLiteCloudOperationalError, # SQLITE_CANTOPEN_FULLPATH
1038: SQLiteCloudOperationalError, # SQLITE_CANTOPEN_CONVPATH
264: SQLiteCloudOperationalError, # SQLITE_READONLY_RECOVERY
520: SQLiteCloudOperationalError, # SQLITE_READONLY_CANTLOCK
776: SQLiteCloudOperationalError, # SQLITE_READONLY_ROLLBACK
1032: SQLiteCloudOperationalError, # SQLITE_READONLY_DBMOVED
1544: SQLiteCloudOperationalError, # SQLITE_READONLY_DIRECTORY
516: SQLiteCloudOperationalError, # SQLITE_ABORT_ROLLBACK
275: SQLiteCloudIntegrityError, # SQLITE_CONSTRAINT_CHECK
531: SQLiteCloudIntegrityError, # SQLITE_CONSTRAINT_COMMITHOOK
787: SQLiteCloudIntegrityError, # SQLITE_CONSTRAINT_FOREIGNKEY
1043: SQLiteCloudIntegrityError, # SQLITE_CONSTRAINT_FUNCTION
1299: SQLiteCloudIntegrityError, # SQLITE_CONSTRAINT_NOTNULL
1555: SQLiteCloudIntegrityError, # SQLITE_CONSTRAINT_PRIMARYKEY
1811: SQLiteCloudIntegrityError, # SQLITE_CONSTRAINT_TRIGGER
2067: SQLiteCloudIntegrityError, # SQLITE_CONSTRAINT_UNIQUE
2323: SQLiteCloudIntegrityError, # SQLITE_CONSTRAINT_VTAB
2579: SQLiteCloudIntegrityError, # SQLITE_CONSTRAINT_ROWID
779: SQLiteCloudDatabaseError, # SQLITE_CORRUPT_INDEX
523: SQLiteCloudProgrammingError, # SQLITE_CORRUPT_SEQUENCE
3091: SQLiteCloudDataError, # SQLITE_CONSTRAINT_DATATYPE
2835: SQLiteCloudDataError, # SQLITE_CONSTRAINT_PINNED
539: SQLiteCloudWarning, # SQLITE_NOTICE_RECOVER_WAL
283: SQLiteCloudWarning, # SQLITE_NOTICE_RECOVER_ROLLBACK
284: SQLiteCloudWarning, # SQLITE_WARNING_AUTOINDEX
}
error_mapping = {**base_error_mapping, **extended_error_mapping}
# retrieve the corresponding exception based on the error code
exception = error_mapping.get(xerrcode, error_mapping.get(code, SQLiteCloudError))
return exception