| 1 |
"""Exception classes for Geniusql.""" |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
class GeniusqlError(Exception): |
|---|
| 5 |
"""Base class for errors which occur within Geniusql.""" |
|---|
| 6 |
def __init__(self, *args): |
|---|
| 7 |
Exception.__init__(self) |
|---|
| 8 |
self.args = args |
|---|
| 9 |
|
|---|
| 10 |
def __str__(self): |
|---|
| 11 |
return u'\n'.join([unicode(arg) for arg in self.args]) |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
class ReferenceError(GeniusqlError): |
|---|
| 15 |
"""Exception raised when a reference between Tables cannot be found.""" |
|---|
| 16 |
pass |
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class MappingError(GeniusqlError): |
|---|
| 20 |
"""Exception raised when a Table name cannot be mapped to storage. |
|---|
| 21 |
|
|---|
| 22 |
This exception should be raised when a consumer attempts to build |
|---|
| 23 |
a map between a Table class and existing internal storage structures. |
|---|
| 24 |
Other exceptions may be raised when trying to find such a map after |
|---|
| 25 |
it has already (supposedly) been created. That is, the questions |
|---|
| 26 |
"do we have a map?" and "can we create a map?" are distinct. |
|---|
| 27 |
The latter should raise this exception whenever possible. |
|---|
| 28 |
The behavior of the former is not specified. |
|---|
| 29 |
""" |
|---|
| 30 |
pass |
|---|
| 31 |
|
|---|
| 32 |
class OutOfConnectionsError(GeniusqlError): |
|---|
| 33 |
"""Exception raised when a database store has run out of connections.""" |
|---|
| 34 |
pass |
|---|
| 35 |
|
|---|
| 36 |
class TransactionLock(Exception): |
|---|
| 37 |
"""Exception raised when a transaction is requested but not allowed. |
|---|
| 38 |
|
|---|
| 39 |
This is also used as a sentinel by a Database, to signal that a |
|---|
| 40 |
given thread should not start a new transaction because the thread |
|---|
| 41 |
is currently performing schema changes (DDL statements). |
|---|
| 42 |
""" |
|---|
| 43 |
pass |
|---|
| 44 |
|
|---|
| 45 |
class TransactionDisconnected(GeniusqlError): |
|---|
| 46 |
"""Exception raised when a connection has been lost during a transaction. |
|---|
| 47 |
|
|---|
| 48 |
Normally, connections are automatically reset when errors occur. However, |
|---|
| 49 |
when a connection is lost during a transaction, it is assumed that any |
|---|
| 50 |
statements were rolled back when the connection was dropped; therefore, |
|---|
| 51 |
it is almost always unsafe to retry the current statement or proceed |
|---|
| 52 |
with the remaining statements; instead, this exception is raised. |
|---|
| 53 |
""" |
|---|
| 54 |
pass |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
class FeatureWarning(UserWarning): |
|---|
| 58 |
"""Warning about functionality which is not supported by all databases.""" |
|---|
| 59 |
pass |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
def warn(msg, category=FeatureWarning, stacklevel=1): |
|---|
| 63 |
"""Issue a warning, or maybe ignore it or raise an exception.""" |
|---|
| 64 |
import warnings |
|---|
| 65 |
warnings.warn(msg, category, stacklevel + 1) |
|---|
| 66 |
|
|---|