]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
qapi: Improve reporting of invalid 'if' errors
authorMarkus Armbruster <armbru@redhat.com>
Fri, 27 Sep 2019 13:46:31 +0000 (15:46 +0200)
committerMarkus Armbruster <armbru@redhat.com>
Sat, 28 Sep 2019 15:17:19 +0000 (17:17 +0200)
Move check_if() from check_keys() to check_exprs() and call it later,
so its error messages gain an "in definition" line.

Checking values in a function named check_keys() is unclean anyway.
The original sin was commit 0545f6b887 "qapi: Better error messages
for bad expressions", which checks the value of key 'name'.  More
sinning in commit 2cbf09925a "qapi: More rigorous checking for type
safety bypass", commit c818408e44 "qapi: Implement boxed types for
commands/events", and commit 967c885108 "qapi: add 'if' to top-level
expressions".  This commit does penance for the latter.  The next
commits will do penance for the others.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20190927134639.4284-19-armbru@redhat.com>

scripts/qapi/common.py
tests/qapi-schema/bad-if-empty-list.err
tests/qapi-schema/bad-if-empty.err
tests/qapi-schema/bad-if-list.err
tests/qapi-schema/bad-if.err

index 2e1d8158d67db8b2fb3d0e66c93f7a0533bfde99..8f96974f85b2f684f47207aa83953da31caee5ee 100644 (file)
@@ -925,8 +925,6 @@ def check_keys(expr, info, meta, required, optional=[]):
             raise QAPISemError(info,
                                "'%s' of %s '%s' should only use true value"
                                % (key, meta, name))
-        if key == 'if':
-            check_if(expr, info)
 
 
 def normalize_enum(expr):
@@ -1028,6 +1026,8 @@ def check_exprs(exprs):
         else:
             assert False, 'unexpected meta type'
 
+        check_if(expr, info)
+
         if doc:
             doc.check_expr(expr)
 
index 75fe6497bc19accc2af7904d011b9720b9c858b5..2218c9279b5d10f3c5228ac44d5553bde5aabbfe 100644 (file)
@@ -1 +1,2 @@
+tests/qapi-schema/bad-if-empty-list.json: In struct 'TestIfStruct':
 tests/qapi-schema/bad-if-empty-list.json:2: 'if' condition [] is useless
index 358bdc3e5117c2fbcc2d55571ce62c7477c4651a..a3fdb3009da46c02db2748a1e7f42c40473d4edc 100644 (file)
@@ -1 +1,2 @@
+tests/qapi-schema/bad-if-empty.json: In struct 'TestIfStruct':
 tests/qapi-schema/bad-if-empty.json:2: 'if' condition '' makes no sense
index 53af0990834b2f6e2a25f9f18f759f8fc93c91a8..e03bf0fc3a8fb68bbfc436ec97049c6eecdb3e7c 100644 (file)
@@ -1 +1,2 @@
+tests/qapi-schema/bad-if-list.json: In struct 'TestIfStruct':
 tests/qapi-schema/bad-if-list.json:2: 'if' condition ' ' makes no sense
index c2e3f5f44c6360c17939e0d90db739c6018a9b72..190216c10986818f5a86c285e98ad12951c31790 100644 (file)
@@ -1 +1,2 @@
+tests/qapi-schema/bad-if.json: In struct 'TestIfStruct':
 tests/qapi-schema/bad-if.json:2: 'if' condition must be a string or a list of strings