Fix parse_key_from_error_msg to not error out on non-string keys

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2018-11-05 13:45:15 -08:00
parent 4682e766a3
commit dce70a5566
2 changed files with 17 additions and 1 deletions

View File

@ -330,7 +330,10 @@ def handle_generic_error(error, path):
def parse_key_from_error_msg(error):
return error.message.split("'")[1]
try:
return error.message.split("'")[1]
except IndexError:
return error.message.split('(')[1].split(' ')[0].strip("'")
def path_string(path):

View File

@ -613,6 +613,19 @@ class ConfigTest(unittest.TestCase):
excinfo.exconly()
)
def test_config_integer_service_property_raise_validation_error(self):
with pytest.raises(ConfigurationError) as excinfo:
config.load(
build_config_details({
'version': '2.1',
'services': {'foobar': {'image': 'busybox', 1234: 'hah'}}
}, 'working_dir', 'filename.yml')
)
assert (
"Unsupported config option for services.foobar: '1234'" in excinfo.exconly()
)
def test_config_invalid_service_name_raise_validation_error(self):
with pytest.raises(ConfigurationError) as excinfo:
config.load(