mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
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:
commit
6de6dc733d
@ -22,6 +22,7 @@ from pkg_resources import iter_entry_points, ResolutionError
|
||||
|
||||
import bigchaindb
|
||||
from bigchaindb.consensus import AbstractConsensusRules
|
||||
from bigchaindb import exceptions
|
||||
|
||||
# TODO: move this to a proper configuration file for logging
|
||||
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))
|
||||
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))
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
"""Custom exceptions used in the `bigchaindb` package.
|
||||
"""
|
||||
|
||||
class ConfigurationError(Exception):
|
||||
"""Raised when there is a problem with server configuration"""
|
||||
|
||||
|
||||
class OperationError(Exception):
|
||||
"""Raised when an operation cannot go through"""
|
||||
|
@ -229,6 +229,13 @@ def test_file_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():
|
||||
from bigchaindb.config_utils import write_config, CONFIG_DEFAULT_PATH
|
||||
m = mock_open()
|
||||
|
Loading…
x
Reference in New Issue
Block a user