From dce70a55668f8c36d6543341d16c1c5f9545b07b Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Mon, 5 Nov 2018 13:45:15 -0800 Subject: [PATCH] Fix parse_key_from_error_msg to not error out on non-string keys Signed-off-by: Joffrey F --- compose/config/validation.py | 5 ++++- tests/unit/config/config_test.py | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/compose/config/validation.py b/compose/config/validation.py index 87c1f2345..039569551 100644 --- a/compose/config/validation.py +++ b/compose/config/validation.py @@ -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): diff --git a/tests/unit/config/config_test.py b/tests/unit/config/config_test.py index 3d7235d58..a6219b200 100644 --- a/tests/unit/config/config_test.py +++ b/tests/unit/config/config_test.py @@ -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(