diff --git a/qemu/scripts/qapi-gen.py b/qemu/scripts/qapi-gen.py index 51b04a07..9726b60a 100644 --- a/qemu/scripts/qapi-gen.py +++ b/qemu/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 # Unicorn: commented out @@ -40,7 +40,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/qemu/scripts/qapi/common.py b/qemu/scripts/qapi/common.py index c866d57d..d5087946 100644 --- a/qemu/scripts/qapi/common.py +++ b/qemu/scripts/qapi/common.py @@ -16,7 +16,6 @@ import errno import os import re import string -import sys try: from collections import OrderedDict except: @@ -1468,19 +1467,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