mirror of https://github.com/docker/compose.git
Clean error.message
Unfortunately the way that jsonschema is calling %r on its property and then encoding the complete message means I've had to do this manual way of removing the literal string prefix, u'. eg: key = 'extends' message = "Invalid value for %r" % key error.message = message.encode("utf-8")" results in: "Invalid value for u'extends'" Performing a replace to strip out the extra "u'", does not change the encoding of the string, it is at this point the character u followed by a '. Signed-off-by: Mazz Mosley <mazz@houseofmnowster.com>
This commit is contained in:
parent
b4872de213
commit
ece6a72712
|
@ -52,6 +52,9 @@ def process_errors(errors):
|
|||
def _parse_key_from_error_msg(error):
|
||||
return error.message.split("'")[1]
|
||||
|
||||
def _clean_error_message(message):
|
||||
return message.replace("u'", "'")
|
||||
|
||||
root_msgs = []
|
||||
invalid_keys = []
|
||||
required = []
|
||||
|
@ -68,7 +71,7 @@ def process_errors(errors):
|
|||
msg = "Invalid service name '{}' - only {} characters are allowed".format(invalid_service_name, VALID_NAME_CHARS)
|
||||
root_msgs.append(msg)
|
||||
else:
|
||||
root_msgs.append(error.message)
|
||||
root_msgs.append(_clean_error_message(error.message))
|
||||
|
||||
else:
|
||||
# handle service level errors
|
||||
|
@ -83,7 +86,7 @@ def process_errors(errors):
|
|||
elif 'image' not in error.instance and 'build' not in error.instance:
|
||||
required.append("Service '{}' has neither an image nor a build path specified. Exactly one must be provided.".format(service_name))
|
||||
else:
|
||||
required.append(error.message)
|
||||
required.append(_clean_error_message(error.message))
|
||||
elif error.validator == 'oneOf':
|
||||
config_key = error.path[1]
|
||||
valid_types = [context.validator_value for context in error.context]
|
||||
|
@ -104,7 +107,7 @@ def process_errors(errors):
|
|||
root_msgs.append("Service '{}' doesn\'t have any configuration options. All top level keys in your docker-compose.yml must map to a dictionary of configuration options.'".format(config_key))
|
||||
elif error.validator == 'required':
|
||||
config_key = error.path[1]
|
||||
required.append("Service '{}' option '{}' is invalid, {}".format(service_name, config_key, error.message))
|
||||
required.append("Service '{}' option '{}' is invalid, {}".format(service_name, config_key, _clean_error_message(error.message)))
|
||||
elif error.validator == 'dependencies':
|
||||
dependency_key = error.validator_value.keys()[0]
|
||||
required_keys = ",".join(error.validator_value[dependency_key])
|
||||
|
|
|
@ -659,7 +659,7 @@ class ExtendsTest(unittest.TestCase):
|
|||
)
|
||||
|
||||
def test_extends_validation_missing_service_key(self):
|
||||
with self.assertRaisesRegexp(ConfigurationError, "u'service' is a required property"):
|
||||
with self.assertRaisesRegexp(ConfigurationError, "'service' is a required property"):
|
||||
config.load(
|
||||
config.ConfigDetails(
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue