qapi: Tweak error messages for missing / conflicting meta-type
authorMarkus Armbruster <armbru@redhat.com>
Tue, 31 Aug 2021 12:38:08 +0000 (14:38 +0200)
committerMarkus Armbruster <armbru@redhat.com>
Fri, 3 Sep 2021 15:09:10 +0000 (17:09 +0200)
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20210831123809.1107782-12-armbru@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
scripts/qapi/expr.py
tests/qapi-schema/double-type.err
tests/qapi-schema/missing-type.err

index 9e2aa1d43a008f137cbebe8fa737c84d199f9e77..ae4437ba08e5af7524b2dc6b1a34bae821159410 100644 (file)
@@ -630,20 +630,15 @@ def check_exprs(exprs: List[_JSONObject]) -> List[_JSONObject]:
         if 'include' in expr:
             continue
 
-        if 'enum' in expr:
-            meta = 'enum'
-        elif 'union' in expr:
-            meta = 'union'
-        elif 'alternate' in expr:
-            meta = 'alternate'
-        elif 'struct' in expr:
-            meta = 'struct'
-        elif 'command' in expr:
-            meta = 'command'
-        elif 'event' in expr:
-            meta = 'event'
-        else:
-            raise QAPISemError(info, "expression is missing metatype")
+        metas = expr.keys() & {'enum', 'struct', 'union', 'alternate',
+                               'command', 'event'}
+        if len(metas) != 1:
+            raise QAPISemError(
+                info,
+                "expression must have exactly one key"
+                " 'enum', 'struct', 'union', 'alternate',"
+                " 'command', 'event'")
+        meta = metas.pop()
 
         check_name_is_str(expr[meta], info, "'%s'" % meta)
         name = cast(str, expr[meta])
index 576e716197c581df5aa162174490df2daebe1705..6a1e8a599036ad683cc79a8744e0886068d8d6af 100644 (file)
@@ -1,3 +1 @@
-double-type.json: In struct 'Bar':
-double-type.json:2: struct has unknown key 'command'
-Valid keys are 'base', 'data', 'features', 'if', 'struct'.
+double-type.json:2: expression must have exactly one key 'enum', 'struct', 'union', 'alternate', 'command', 'event'
index 5755386a18897c3574dd5a541b7dda847405e92d..cb39569e49027f02ac4f1b3a60299ba3857922cd 100644 (file)
@@ -1 +1 @@
-missing-type.json:2: expression is missing metatype
+missing-type.json:2: expression must have exactly one key 'enum', 'struct', 'union', 'alternate', 'command', 'event'