From: Mark Hymers Date: Sat, 30 Jul 2011 21:26:52 +0000 (+0100) Subject: Give slightly nicer error message on db conn failure X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5bc0b3dccd5874054ad585157cbe2b05758b654;p=dak Give slightly nicer error message on db conn failure Signed-off-by: Mark Hymers --- diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 6d954c88..7e9ff539 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -3664,15 +3664,21 @@ class DBConn(object): sqlalchemy.dialects.postgresql.base.dialect = PGDialect_psycopg2_dak - self.db_pg = create_engine(connstr, **engine_args) - self.db_meta = MetaData() - self.db_meta.bind = self.db_pg - self.db_smaker = sessionmaker(bind=self.db_pg, - autoflush=True, - autocommit=False) - - self.__setuptables() - self.__setupmappers() + try: + self.db_pg = create_engine(connstr, **engine_args) + self.db_meta = MetaData() + self.db_meta.bind = self.db_pg + self.db_smaker = sessionmaker(bind=self.db_pg, + autoflush=True, + autocommit=False) + + self.__setuptables() + self.__setupmappers() + + except OperationalError, e: + import utils + utils.fubar("Cannot connect to database (%s)" % str(e)) + self.pid = os.getpid() def session(self, work_mem = 0):