Skip to content

Commit

Permalink
qapi: Improve error position for bogus invalid "Returns" section
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Markus Armbruster committed Feb 26, 2024
1 parent 15333ab commit bf00dc1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions scripts/qapi/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,9 +759,13 @@ def connect_feature(self, feature: 'QAPISchemaFeature') -> None:
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:

Expand Down
2 changes: 1 addition & 1 deletion tests/qapi-schema/doc-invalid-return.err
Original file line number Diff line number Diff line change
@@ -1 +1 @@
doc-invalid-return.json:3: 'Returns:' is only valid for commands
doc-invalid-return.json:5: 'Returns:' is only valid for commands

0 comments on commit bf00dc1

Please sign in to comment.