From bf00dc19f3aacf014b308d57bb0debf250339396 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 16 Feb 2024 15:58:30 +0100 Subject: qapi: Improve error position for bogus invalid "Returns" section MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Message-ID: <20240216145841.2099240-7-armbru@redhat.com> Reviewed-by: Daniel P. Berrangé --- scripts/qapi/parser.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'scripts/qapi/parser.py') 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: -- cgit 1.4.1