summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/exc.py
diff options
context:
space:
mode:
authorDiana Clarke <diana.joan.clarke@gmail.com>2012-11-19 19:06:47 -0500
committerDiana Clarke <diana.joan.clarke@gmail.com>2012-11-19 19:06:47 -0500
commit648778afb2d8c3314dbad83438954d69dfa48b7b (patch)
treeaa42ab66439cf7f226c2afccde30fbc0f51f25c7 /lib/sqlalchemy/exc.py
parent80ece085260ecef3f0cb623e8873e3aec0b2a231 (diff)
downloadsqlalchemy-648778afb2d8c3314dbad83438954d69dfa48b7b.tar.gz
just a pep8 pass of lib/sqlalchemy/
Diffstat (limited to 'lib/sqlalchemy/exc.py')
-rw-r--r--lib/sqlalchemy/exc.py54
1 files changed, 37 insertions, 17 deletions
diff --git a/lib/sqlalchemy/exc.py b/lib/sqlalchemy/exc.py
index 3c4a64704..1334d63f2 100644
--- a/lib/sqlalchemy/exc.py
+++ b/lib/sqlalchemy/exc.py
@@ -6,14 +6,15 @@
"""Exceptions used with SQLAlchemy.
-The base exception class is :class:`.SQLAlchemyError`. Exceptions which are raised as a
-result of DBAPI exceptions are all subclasses of
+The base exception class is :class:`.SQLAlchemyError`. Exceptions which are
+raised as a result of DBAPI exceptions are all subclasses of
:class:`.DBAPIError`.
"""
import traceback
+
class SQLAlchemyError(Exception):
"""Generic error class."""
@@ -25,14 +26,17 @@ class ArgumentError(SQLAlchemyError):
"""
+
class NoForeignKeysError(ArgumentError):
"""Raised when no foreign keys can be located between two selectables
during a join."""
+
class AmbiguousForeignKeysError(ArgumentError):
"""Raised when more than one foreign key matching can be located
between two selectables during a join."""
+
class CircularDependencyError(SQLAlchemyError):
"""Raised by topological sorts when a circular dependency is detected.
@@ -64,9 +68,11 @@ class CircularDependencyError(SQLAlchemyError):
return self.__class__, (None, self.cycles,
self.edges, self.args[0])
+
class CompileError(SQLAlchemyError):
"""Raised when an error occurs during SQL compilation"""
+
class IdentifierError(SQLAlchemyError):
"""Raised when a schema name is beyond the max character limit"""
@@ -75,15 +81,14 @@ class DisconnectionError(SQLAlchemyError):
"""A disconnect is detected on a raw DB-API connection.
This error is raised and consumed internally by a connection pool. It can
- be raised by the :meth:`.PoolEvents.checkout` event
- so that the host pool forces a retry; the exception will be caught
- three times in a row before the pool gives up and raises
- :class:`~sqlalchemy.exc.InvalidRequestError` regarding the connection attempt.
+ be raised by the :meth:`.PoolEvents.checkout` event so that the host pool
+ forces a retry; the exception will be caught three times in a row before
+ the pool gives up and raises :class:`~sqlalchemy.exc.InvalidRequestError`
+ regarding the connection attempt.
"""
-
class TimeoutError(SQLAlchemyError):
"""Raised when a connection pool times out on getting a connection."""
@@ -95,23 +100,30 @@ class InvalidRequestError(SQLAlchemyError):
"""
+
class NoInspectionAvailable(InvalidRequestError):
"""A subject passed to :func:`sqlalchemy.inspection.inspect` produced
no context for inspection."""
+
class ResourceClosedError(InvalidRequestError):
"""An operation was requested from a connection, cursor, or other
object that's in a closed state."""
+
class NoSuchColumnError(KeyError, InvalidRequestError):
"""A nonexistent column is requested from a ``RowProxy``."""
+
class NoReferenceError(InvalidRequestError):
"""Raised by ``ForeignKey`` to indicate a reference cannot be resolved."""
+
class NoReferencedTableError(NoReferenceError):
- """Raised by ``ForeignKey`` when the referred ``Table`` cannot be located."""
+ """Raised by ``ForeignKey`` when the referred ``Table`` cannot be
+ located.
+ """
def __init__(self, message, tname):
NoReferenceError.__init__(self, message)
self.table_name = tname
@@ -119,9 +131,12 @@ class NoReferencedTableError(NoReferenceError):
def __reduce__(self):
return self.__class__, (self.args[0], self.table_name)
+
class NoReferencedColumnError(NoReferenceError):
- """Raised by ``ForeignKey`` when the referred ``Column`` cannot be located."""
+ """Raised by ``ForeignKey`` when the referred ``Column`` cannot be
+ located.
+ """
def __init__(self, message, tname, cname):
NoReferenceError.__init__(self, message)
self.table_name = tname
@@ -131,6 +146,7 @@ class NoReferencedColumnError(NoReferenceError):
return self.__class__, (self.args[0], self.table_name,
self.column_name)
+
class NoSuchTableError(InvalidRequestError):
"""Table does not exist or is not visible to a connection."""
@@ -166,6 +182,7 @@ if sys.version_info < (2, 5):
# Moved to orm.exc; compatibility definition installed by orm import until 0.6
UnmappedColumnError = None
+
class StatementError(SQLAlchemyError):
"""An error occurred during execution of a SQL statement.
@@ -207,6 +224,7 @@ class StatementError(SQLAlchemyError):
def __unicode__(self):
return self.__str__()
+
class DBAPIError(StatementError):
"""Raised when the execution of a database operation fails.
@@ -219,13 +237,14 @@ class DBAPIError(StatementError):
raise the same exception type for any given error condition.
:class:`DBAPIError` features :attr:`~.StatementError.statement`
- and :attr:`~.StatementError.params` attributes which supply context regarding
- the specifics of the statement which had an issue, for the
+ and :attr:`~.StatementError.params` attributes which supply context
+ regarding the specifics of the statement which had an issue, for the
typical case when the error was raised within the context of
emitting a SQL statement.
- The wrapped exception object is available in the :attr:`~.StatementError.orig` attribute.
- Its type and properties are DB-API implementation specific.
+ The wrapped exception object is available in the
+ :attr:`~.StatementError.orig` attribute. Its type and properties are
+ DB-API implementation specific.
"""
@@ -243,11 +262,12 @@ class DBAPIError(StatementError):
# not a DBAPI error, statement is present.
# raise a StatementError
if not isinstance(orig, dbapi_base_err) and statement:
+ msg = traceback.format_exception_only(
+ orig.__class__, orig)[-1].strip()
return StatementError(
- "%s (original cause: %s)" % (
- str(orig),
- traceback.format_exception_only(orig.__class__, orig)[-1].strip()
- ), statement, params, orig)
+ "%s (original cause: %s)" % (str(orig), msg),
+ statement, params, orig
+ )
name, glob = orig.__class__.__name__, globals()
if name in glob and issubclass(glob[name], DBAPIError):