qapi: Fix error message when type name or array is expected
authorMarkus Armbruster <armbru@redhat.com>
Thu, 16 Mar 2023 07:13:18 +0000 (08:13 +0100)
committerMarkus Armbruster <armbru@redhat.com>
Mon, 24 Apr 2023 13:21:39 +0000 (15:21 +0200)
We incorrectly report "FOO should be a type name" when it could also
be an array.  Fix that.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20230316071325.492471-8-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
scripts/qapi/expr.py
tests/qapi-schema/event-nest-struct.err
tests/qapi-schema/nested-struct-data.err
tests/qapi-schema/returns-dict.err
tests/qapi-schema/struct-member-invalid.err

index 8a8de9e3aabe997f87ebb8de17a5def474c9fa8d..9bae500a7dbb15ac60b4259b0ea54efa0cf85c52 100644 (file)
@@ -344,15 +344,14 @@ def check_type_name_or_array(value: Optional[object],
     if value is None or isinstance(value, str):
         return
 
-    if isinstance(value, list):
-        if len(value) != 1 or not isinstance(value[0], str):
-            raise QAPISemError(info,
-                               "%s: array type must contain single type name" %
-                               source)
-        return
+    if not isinstance(value, list):
+        raise QAPISemError(info,
+                           "%s should be a type name or array" % source)
 
-    raise QAPISemError(info,
-                       "%s should be a type name" % source)
+    if len(value) != 1 or not isinstance(value[0], str):
+        raise QAPISemError(info,
+                           "%s: array type must contain single type name" %
+                           source)
 
 
 def check_type_name_or_implicit(value: Optional[object],
index 8c5f6ed311df9c63d4ffaa395b4b82badd3c0eb3..15fc1406f86efbc3c3d8de7feb41b789b860c364 100644 (file)
@@ -1,2 +1,2 @@
 event-nest-struct.json: In event 'EVENT_A':
-event-nest-struct.json:1: 'data' member 'a' should be a type name
+event-nest-struct.json:1: 'data' member 'a' should be a type name or array
index c7258a0182b2b95fef976385332d03f815f7ad75..7dc5c7cb2d72147cfdd34862f9a267a720aa8416 100644 (file)
@@ -1,2 +1,2 @@
 nested-struct-data.json: In command 'foo':
-nested-struct-data.json:2: 'data' member 'a' should be a type name
+nested-struct-data.json:2: 'data' member 'a' should be a type name or array
index 9b2d90c010d5f35e60144ab46cee49cf6302dac8..bf160e754b1cbd77e861ca4fdff616b0c620238f 100644 (file)
@@ -1,2 +1,2 @@
 returns-dict.json: In command 'oops':
-returns-dict.json:2: 'returns' should be a type name
+returns-dict.json:2: 'returns' should be a type name or array
index 7e01a41d7c74a7d593bd01ea3e7d8137ef1b4e8a..3130d69d9fc49441a9bc5cf763be3f6c7c035786 100644 (file)
@@ -1,2 +1,2 @@
 struct-member-invalid.json: In struct 'Foo':
-struct-member-invalid.json:1: 'data' member 'a' should be a type name
+struct-member-invalid.json:1: 'data' member 'a' should be a type name or array