[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 13/30] qapi: Lift error reporting from QAPISchema.__i
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PULL 13/30] qapi: Lift error reporting from QAPISchema.__init__() to callers |
Date: |
Thu, 1 Mar 2018 13:42:28 -0600 |
From: Markus Armbruster <address@hidden>
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Marc-André Lureau <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Michael Roth <address@hidden>
Signed-off-by: Eric Blake <address@hidden>
---
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=sys.stderr)
sys.exit(1)
- schema = QAPISchema(args.schema)
+ try:
+ schema = QAPISchema(args.schema)
+ except QAPIError as err:
+ print(err, file=sys.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 = QAPISchemaParser(open(fname, 'r'))
- exprs = check_exprs(parser.exprs)
- self.docs = parser.docs
- self._entity_dict = {}
- self._predefining = True
- self._def_predefineds()
- self._predefining = False
- self._def_exprs(exprs)
- self.check()
- except QAPIError as err:
- print(err, file=sys.stderr)
- exit(1)
+ parser = QAPISchemaParser(open(fname, 'r'))
+ exprs = check_exprs(parser.exprs)
+ self.docs = parser.docs
+ self._entity_dict = {}
+ self._predefining = True
+ self._def_predefineds()
+ self._predefining = 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 = QAPISchema(sys.argv[1])
+
+try:
+ schema = QAPISchema(sys.argv[1])
+except QAPIError as err:
+ print(err, file=sys.stderr)
+ exit(1)
+
schema.visit(QAPISchemaTestVisitor())
for doc in schema.docs:
--
2.14.3
- [Qemu-devel] [PULL 01/30] Include qapi/qmp/qerror.h exactly where needed, (continued)
- [Qemu-devel] [PULL 01/30] Include qapi/qmp/qerror.h exactly where needed, Eric Blake, 2018/03/01
- [Qemu-devel] [PULL 04/30] qapi: Rename variable holding the QAPISchemaGenFOOVisitor, Eric Blake, 2018/03/01
- [Qemu-devel] [PULL 03/30] qapi: Generate up-to-date copyright notice, Eric Blake, 2018/03/01
- [Qemu-devel] [PULL 02/30] qapi: Streamline boilerplate comment generation, Eric Blake, 2018/03/01
- [Qemu-devel] [PULL 07/30] qapi: Turn generators into modules, Eric Blake, 2018/03/01
- [Qemu-devel] [PULL 09/30] qapi-gen: Convert from getopt to argparse, Eric Blake, 2018/03/01
- [Qemu-devel] [PULL 05/30] qapi: New classes QAPIGenC, QAPIGenH, QAPIGenDoc, Eric Blake, 2018/03/01
- [Qemu-devel] [PULL 06/30] qapi: Reduce use of global variables in generators some, Eric Blake, 2018/03/01
- [Qemu-devel] [PULL 10/30] qapi: Touch generated files only when they change, Eric Blake, 2018/03/01
- [Qemu-devel] [PULL 12/30] qapi/common: Eliminate QAPISchema.exprs, Eric Blake, 2018/03/01
- [Qemu-devel] [PULL 13/30] qapi: Lift error reporting from QAPISchema.__init__() to callers,
Eric Blake <=
- [Qemu-devel] [PULL 15/30] qapi: Record 'include' directives in parse tree, Eric Blake, 2018/03/01
- [Qemu-devel] [PULL 11/30] qapi: Improve include file name reporting in error messages, Eric Blake, 2018/03/01
- [Qemu-devel] [PULL 08/30] qapi-gen: New common driver for code and doc generators, Eric Blake, 2018/03/01
- [Qemu-devel] [PULL 14/30] qapi: Concentrate QAPISchemaParser.exprs updates in .__init__(), Eric Blake, 2018/03/01
- [Qemu-devel] [PULL 16/30] qapi: Generate in source order, Eric Blake, 2018/03/01
- [Qemu-devel] [PULL 17/30] qapi: Record 'include' directives in intermediate representation, Eric Blake, 2018/03/01
- [Qemu-devel] [PULL 18/30] qapi: Rename generated qmp-marshal.c to qmp-commands.c, Eric Blake, 2018/03/01
- [Qemu-devel] [PULL 21/30] qapi/common: Fix guardname() for funny filenames, Eric Blake, 2018/03/01
- [Qemu-devel] [PULL 20/30] qapi/types qapi/visit: Generate built-in stuff into separate files, Eric Blake, 2018/03/01
- [Qemu-devel] [PULL 19/30] qapi: Make code-generating visitors use QAPIGen more, Eric Blake, 2018/03/01