1. mixmastamyk
  2. dumbo
  3. Issues
Issue #5 open

log more info when DB connection fails

robnewton
created an issue

class DbConnector raises a RuntimeError when when the DB module cannot be imported.

This is called in class DumboFrame: {{{

!python

    # populate sidebar
    try:
        self.db = DbConnector(self.config['dbtype']['module'])
    except (TypeError, IndexError, RuntimeError, KeyError), e:
        log.warning('Unable to connect to database using config.')
        self.db = None

}}}

It would be good to include the exception message in the logged message in the log file, so we can tell what the problem is. (In my case, the psycopg2 module was not installed).

Comments (3)

  1. mixmastamyk repo owner
    • changed status to open

    Good idea, how's this?

            try:
                self.db = DbConnector(self.config['dbtype']['module'])
            except (TypeError, IndexError, RuntimeError, KeyError), e:
                log.error('%s: %s' % (e.__class__.__name__, e))
                log.warn('Unable to connect to database using config, falling ' +
                    'back to demo mode.')
    
  2. robnewton reporter

    That's good. But for your next revision, it would be good if you could change line 191 from:

    raise RuntimeError, 'Database API module not found.'
    

    to:

    raise RuntimeError, 'Database API module not found.' + str(e)
    

    Cheers!

  3. Log in to comment