From 08d5f3bc029d07e78e1f38b822ad9a3ef21770ad Mon Sep 17 00:00:00 2001 From: Roman Podoliaka Date: Mon, 10 Oct 2016 15:13:19 +0300 Subject: Add a specific exception for 'unknown database' errors Add an exception filter to distinguish 'unknown database' errors from other DBAPIError's. This effectively means we no longer unconditionally print a traceback to logs, when someone tries to connect to a database, that does not exist, but just raise a specific exception instead and let the caller handle it. Closes-Bug: #1631033 Change-Id: Iebc1ec1e8153917fbcde116d04bc171272993bbd --- oslo_db/exception.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'oslo_db/exception.py') diff --git a/oslo_db/exception.py b/oslo_db/exception.py index 2d118cd..e66fe98 100644 --- a/oslo_db/exception.py +++ b/oslo_db/exception.py @@ -155,6 +155,18 @@ class DBNonExistentTable(DBError): super(DBNonExistentTable, self).__init__(inner_exception) +class DBNonExistentDatabase(DBError): + """Database does not exist. + + :param database: database name + :type database: str + """ + + def __init__(self, database, inner_exception=None): + self.database = database + super(DBNonExistentDatabase, self).__init__(inner_exception) + + class DBDeadlock(DBError): """Database dead lock error. -- cgit v1.2.1