qapi: Improve error position for bogus invalid "Returns" section
authorMarkus Armbruster <armbru@redhat.com>
Fri, 16 Feb 2024 14:58:30 +0000 (15:58 +0100)
committerMarkus Armbruster <armbru@redhat.com>
Mon, 26 Feb 2024 09:43:56 +0000 (10:43 +0100)
When something other than a command has a "Returns" section, the error
message points to the beginning of the definition comment.  Point to
the "Returns" section instead.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20240216145841.2099240-7-armbru@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
scripts/qapi/parser.py
tests/qapi-schema/doc-invalid-return.err

index 82db595dcfe26aa126d7191ad47bec9c3927aad9..a7710139599b751d00a170b51f05890601cffe61 100644 (file)
@@ -759,9 +759,13 @@ class QAPIDoc:
         self.features[feature.name].connect(feature)
 
     def check_expr(self, expr: QAPIExpression) -> None:
-        if self.has_section('Returns') and 'command' not in expr:
-            raise QAPISemError(self.info,
-                               "'Returns:' is only valid for commands")
+        if 'command' not in expr:
+            sec = next((sec for sec in self.sections
+                        if sec.name == 'Returns'),
+                       None)
+            if sec:
+                raise QAPISemError(sec.info,
+                                   "'Returns:' is only valid for commands")
 
     def check(self) -> None:
 
index 2ad89c594110e1dfd928b56c20750a7e3e098b27..bc5826de20b1b2c2738c7617ebe39652a1132f36 100644 (file)
@@ -1 +1 @@
-doc-invalid-return.json:3: 'Returns:' is only valid for commands
+doc-invalid-return.json:5: 'Returns:' is only valid for commands