mirror of https://github.com/docker/compose.git
Fix ports validation message
- The `raises` kwarg to the `cls_check` decorator was being used incorrectly (it should be an exception class, not an object). - We need to check for `error.cause` and get the message out of the exception object. NB: The particular case where validation fails in the case of `ports` is only when ranges don't match in length - no further validation is currently performed client-side. Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
parent
d52508e2b1
commit
374b16843f
|
@ -36,16 +36,12 @@ DOCKER_CONFIG_HINTS = {
|
|||
VALID_NAME_CHARS = '[a-zA-Z0-9\._\-]'
|
||||
|
||||
|
||||
@FormatChecker.cls_checks(
|
||||
format="ports",
|
||||
raises=ValidationError(
|
||||
"Invalid port formatting, it should be "
|
||||
"'[[remote_ip:]remote_port:]port[/protocol]'"))
|
||||
@FormatChecker.cls_checks(format="ports", raises=ValidationError)
|
||||
def format_ports(instance):
|
||||
try:
|
||||
split_port(instance)
|
||||
except ValueError:
|
||||
return False
|
||||
except ValueError as e:
|
||||
raise ValidationError(six.text_type(e))
|
||||
return True
|
||||
|
||||
|
||||
|
@ -184,6 +180,10 @@ def handle_generic_service_error(error, service_name):
|
|||
config_key,
|
||||
required_keys)
|
||||
|
||||
elif error.cause:
|
||||
error_msg = six.text_type(error.cause)
|
||||
msg_format = "Service '{}' configuration key {} is invalid: {}"
|
||||
|
||||
elif error.path:
|
||||
msg_format = "Service '{}' configuration key {} value {}"
|
||||
|
||||
|
|
Loading…
Reference in New Issue