aboutsummaryrefslogtreecommitdiff
path: root/scripts/qapi/parser.py
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2024-02-16 15:58:30 +0100
committerMarkus Armbruster <armbru@redhat.com>2024-02-26 10:43:56 +0100
commitbf00dc19f3aacf014b308d57bb0debf250339396 (patch)
tree64ce6eb2bab7a32ea06d1aabef8a5fbd641c8a54 /scripts/qapi/parser.py
parent15333abed9112f99e0b1af4327154af733b987d3 (diff)
qapi: Improve error position for bogus invalid "Returns" section
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>
Diffstat (limited to 'scripts/qapi/parser.py')
-rw-r--r--scripts/qapi/parser.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
index 82db595dcf..a771013959 100644
--- a/scripts/qapi/parser.py
+++ b/scripts/qapi/parser.py
@@ -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: