瀏覽代碼

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 <[email protected]>
Aanand Prasad 10 年之前
父節點
當前提交
374b16843f
共有 1 個文件被更改,包括 7 次插入7 次删除
  1. 7 7
      compose/config/validation.py

+ 7 - 7
compose/config/validation.py

@@ -36,16 +36,12 @@ DOCKER_CONFIG_HINTS = {
 VALID_NAME_CHARS = '[a-zA-Z0-9\._\-]'
 
 
[email protected]_checks(
-    format="ports",
-    raises=ValidationError(
-        "Invalid port formatting, it should be "
-        "'[[remote_ip:]remote_port:]port[/protocol]'"))
[email protected]_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 {}"