Merge branch 'bug/419/config-syntax-error-pretty-message' of https://github.com/d01phin/bigchaindb into d01phin-bug/419/config-syntax-error-pretty-messagee

This commit is contained in:
vrde 2016-08-19 15:28:00 +02:00
commit 6de6dc733d
No known key found for this signature in database
GPG Key ID: 6581C7C39B3D397D
3 changed files with 17 additions and 1 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)
@ -98,7 +99,12 @@ def file_config(filename=None):
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: with open(filename) as f:
config = json.load(f) try:
config = json.load(f)
except ValueError as err:
raise exceptions.ConfigurationError(
'Failed to parse the JSON configuration from `{}`, {}'.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"""

View File

@ -229,6 +229,13 @@ def test_file_config():
assert config == {} assert config == {}
def test_invalid_file_config():
from bigchaindb.config_utils import file_config, CONFIG_DEFAULT_PATH
with patch('builtins.open', mock_open(read_data='{_INVALID_JSON_}')) as m:
with pytest.raises(exceptions.ConfigurationError):
file_config()
def test_write_config(): def test_write_config():
from bigchaindb.config_utils import write_config, CONFIG_DEFAULT_PATH from bigchaindb.config_utils import write_config, CONFIG_DEFAULT_PATH
m = mock_open() m = mock_open()