浏览代码

process_errors handle both schemas

Now the schema has been split into two, we need to modify the
process_errors function to accomodate.

Previously if an error.path was empty then it meant they were root
errors. Now that service_schema checks after the service has been
resolved, our service name is a key within the dictionary and
so our root error logic check is no longer true.

Signed-off-by: Mazz Mosley <[email protected]>
Mazz Mosley 10 年之前
父节点
当前提交
9fa6e42f55
共有 1 个文件被更改,包括 8 次插入6 次删除
  1. 8 6
      compose/config/validation.py

+ 8 - 6
compose/config/validation.py

@@ -125,7 +125,7 @@ def process_errors(errors):
 
     for error in errors:
         # handle root level errors
-        if len(error.path) == 0:
+        if len(error.path) == 0 and not error.instance.get('name'):
             if error.validator == 'type':
                 msg = "Top level object needs to be a dictionary. Check your .yml file that you have defined a service at the top level."
                 root_msgs.append(msg)
@@ -137,11 +137,13 @@ def process_errors(errors):
                 root_msgs.append(_clean_error_message(error.message))
 
         else:
-            # handle service level errors
-            service_name = error.path[0]
-
-            # pop the service name off our path
-            error.path.popleft()
+            try:
+                # field_schema errors will have service name on the path
+                service_name = error.path[0]
+                error.path.popleft()
+            except IndexError:
+                # service_schema errors will have the name in the instance
+                service_name = error.instance.get('name')
 
             if error.validator == 'additionalProperties':
                 invalid_config_key = _parse_key_from_error_msg(error)