From nobody Sun Oct 5 19:25:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519934076006123.49216990466232; Thu, 1 Mar 2018 11:54:36 -0800 (PST) Received: from localhost ([::1]:58988 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erUHe-0000rJ-Sy for importer@patchew.org; Thu, 01 Mar 2018 14:54:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40536) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erU6r-0000qz-6S for qemu-devel@nongnu.org; Thu, 01 Mar 2018 14:43:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erU6q-0007as-7F for qemu-devel@nongnu.org; Thu, 01 Mar 2018 14:43:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55794) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erU6p-0007ZC-UW for qemu-devel@nongnu.org; Thu, 01 Mar 2018 14:43:20 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1C55F5F7B1; Thu, 1 Mar 2018 19:43:19 +0000 (UTC) Received: from red.redhat.com (ovpn-122-122.rdu2.redhat.com [10.10.122.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4931C620A8; Thu, 1 Mar 2018 19:43:18 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 1 Mar 2018 13:42:28 -0600 Message-Id: <20180301194245.29854-14-eblake@redhat.com> In-Reply-To: <20180301194245.29854-1-eblake@redhat.com> References: <20180301194245.29854-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 01 Mar 2018 19:43:19 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 13/30] qapi: Lift error reporting from QAPISchema.__init__() to callers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , Markus Armbruster , Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Markus Armbruster Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20180211093607.27351-14-armbru@redhat.com> Reviewed-by: Eric Blake Reviewed-by: Michael Roth Signed-off-by: Eric Blake --- scripts/qapi-gen.py | 8 ++++++-- scripts/qapi/common.py | 23 +++++++++-------------- tests/qapi-schema/test-qapi.py | 10 ++++++++-- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/scripts/qapi-gen.py b/scripts/qapi-gen.py index cb56ba7cff7..3d98ca2e0c6 100755 --- a/scripts/qapi-gen.py +++ b/scripts/qapi-gen.py @@ -8,7 +8,7 @@ from __future__ import print_function import argparse import re import sys -from qapi.common import QAPISchema +from qapi.common import QAPIError, QAPISchema from qapi.types import gen_types from qapi.visit import gen_visit from qapi.commands import gen_commands @@ -39,7 +39,11 @@ def main(argv): file=3Dsys.stderr) sys.exit(1) - schema =3D QAPISchema(args.schema) + try: + schema =3D QAPISchema(args.schema) + except QAPIError as err: + print(err, file=3Dsys.stderr) + exit(1) gen_types(schema, args.output_dir, args.prefix, args.builtins) gen_visit(schema, args.output_dir, args.prefix, args.builtins) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 60a47486065..4cc4d3ee8f4 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -16,7 +16,6 @@ import errno import os import re import string -import sys try: from collections import OrderedDict except: @@ -1459,19 +1458,15 @@ class QAPISchemaEvent(QAPISchemaEntity): class QAPISchema(object): def __init__(self, fname): - try: - parser =3D QAPISchemaParser(open(fname, 'r')) - exprs =3D check_exprs(parser.exprs) - self.docs =3D parser.docs - self._entity_dict =3D {} - self._predefining =3D True - self._def_predefineds() - self._predefining =3D False - self._def_exprs(exprs) - self.check() - except QAPIError as err: - print(err, file=3Dsys.stderr) - exit(1) + parser =3D QAPISchemaParser(open(fname, 'r')) + exprs =3D check_exprs(parser.exprs) + self.docs =3D parser.docs + self._entity_dict =3D {} + self._predefining =3D True + self._def_predefineds() + self._predefining =3D False + self._def_exprs(exprs) + self.check() def _def_entity(self, ent): # Only the predefined types are allowed to not have info diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index bb1b6dd2974..4da14b43af6 100644 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -12,7 +12,7 @@ from __future__ import print_function import sys -from qapi.common import QAPISchema, QAPISchemaVisitor +from qapi.common import QAPIError, QAPISchema, QAPISchemaVisitor class QAPISchemaTestVisitor(QAPISchemaVisitor): @@ -52,7 +52,13 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): for v in variants.variants: print(' case %s: %s' % (v.name, v.type.name)) -schema =3D QAPISchema(sys.argv[1]) + +try: + schema =3D QAPISchema(sys.argv[1]) +except QAPIError as err: + print(err, file=3Dsys.stderr) + exit(1) + schema.visit(QAPISchemaTestVisitor()) for doc in schema.docs: --=20 2.14.3