Add some exception handling to file_config() config loader

This commit is contained in:
David Gasparian 2016-08-07 23:23:40 +04:00
parent 011e840cf5
commit 3f53e67c65
2 changed files with 9 additions and 2 deletions

View File

@ -22,6 +22,7 @@ from pkg_resources import iter_entry_points, ResolutionError
import bigchaindb import bigchaindb
from bigchaindb.consensus import AbstractConsensusRules from bigchaindb.consensus import AbstractConsensusRules
from bigchaindb import exceptions
# TODO: move this to a proper configuration file for logging # TODO: move this to a proper configuration file for logging
logging.getLogger('requests').setLevel(logging.WARNING) logging.getLogger('requests').setLevel(logging.WARNING)
@ -97,8 +98,11 @@ def file_config(filename=None):
filename = CONFIG_DEFAULT_PATH filename = CONFIG_DEFAULT_PATH
logger.debug('file_config() will try to open `{}`'.format(filename)) logger.debug('file_config() will try to open `{}`'.format(filename))
with open(filename) as f: try:
config = json.load(f) with open(filename) as f:
config = json.load(f)
except Exception as err:
raise exceptions.ConfigurationError('Failed to load configuration from `{}`, reason: {}'.format(filename, err))
logger.info('Configuration loaded from `{}`'.format(filename)) logger.info('Configuration loaded from `{}`'.format(filename))

View File

@ -1,6 +1,9 @@
"""Custom exceptions used in the `bigchaindb` package. """Custom exceptions used in the `bigchaindb` package.
""" """
class ConfigurationError(Exception):
"""Raised when there is a problem with server configuration"""
class OperationError(Exception): class OperationError(Exception):
"""Raised when an operation cannot go through""" """Raised when an operation cannot go through"""