[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 11/12] qapi: Tweak error messages for missing / conflicting meta-
From: |
Markus Armbruster |
Subject: |
[PATCH 11/12] qapi: Tweak error messages for missing / conflicting meta-type |
Date: |
Tue, 31 Aug 2021 14:38:08 +0200 |
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
scripts/qapi/expr.py | 23 +++++++++--------------
tests/qapi-schema/double-type.err | 4 +---
tests/qapi-schema/missing-type.err | 2 +-
3 files changed, 11 insertions(+), 18 deletions(-)
diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py
index 9e2aa1d43a..ae4437ba08 100644
--- a/scripts/qapi/expr.py
+++ b/scripts/qapi/expr.py
@@ -630,20 +630,15 @@ def check_exprs(exprs: List[_JSONObject]) ->
List[_JSONObject]:
if 'include' in expr:
continue
- if 'enum' in expr:
- meta = 'enum'
- elif 'union' in expr:
- meta = 'union'
- elif 'alternate' in expr:
- meta = 'alternate'
- elif 'struct' in expr:
- meta = 'struct'
- elif 'command' in expr:
- meta = 'command'
- elif 'event' in expr:
- meta = 'event'
- else:
- raise QAPISemError(info, "expression is missing metatype")
+ metas = expr.keys() & {'enum', 'struct', 'union', 'alternate',
+ 'command', 'event'}
+ if len(metas) != 1:
+ raise QAPISemError(
+ info,
+ "expression must have exactly one key"
+ " 'enum', 'struct', 'union', 'alternate',"
+ " 'command', 'event'")
+ meta = metas.pop()
check_name_is_str(expr[meta], info, "'%s'" % meta)
name = cast(str, expr[meta])
diff --git a/tests/qapi-schema/double-type.err
b/tests/qapi-schema/double-type.err
index 576e716197..6a1e8a5990 100644
--- a/tests/qapi-schema/double-type.err
+++ b/tests/qapi-schema/double-type.err
@@ -1,3 +1 @@
-double-type.json: In struct 'Bar':
-double-type.json:2: struct has unknown key 'command'
-Valid keys are 'base', 'data', 'features', 'if', 'struct'.
+double-type.json:2: expression must have exactly one key 'enum', 'struct',
'union', 'alternate', 'command', 'event'
diff --git a/tests/qapi-schema/missing-type.err
b/tests/qapi-schema/missing-type.err
index 5755386a18..cb39569e49 100644
--- a/tests/qapi-schema/missing-type.err
+++ b/tests/qapi-schema/missing-type.err
@@ -1 +1 @@
-missing-type.json:2: expression is missing metatype
+missing-type.json:2: expression must have exactly one key 'enum', 'struct',
'union', 'alternate', 'command', 'event'
--
2.31.1
- [PATCH 00/12] qapi: Fixes and cleanups for recent work (mostly), Markus Armbruster, 2021/08/31
- [PATCH 07/12] qapi: Avoid redundant parens in code generated for conditionals, Markus Armbruster, 2021/08/31
- [PATCH 01/12] qapi: Simplify QAPISchemaIfCond's interface for generating C, Markus Armbruster, 2021/08/31
- [PATCH 06/12] qapi: Factor common recursion out of cgen_ifcond(), docgen_ifcond(), Markus Armbruster, 2021/08/31
- [PATCH 02/12] qapi: Simplify how QAPISchemaIfCond represents "no condition", Markus Armbruster, 2021/08/31
- [PATCH 05/12] qapi: Fix C code generation for 'if', Markus Armbruster, 2021/08/31
- [PATCH 04/12] tests/qapi-schema: Demonstrate broken C code for 'if', Markus Armbruster, 2021/08/31
- [PATCH 08/12] qapi: Use "not COND" instead of "!COND" for generated documentation, Markus Armbruster, 2021/08/31
- [PATCH 03/12] tests/qapi-schema: Correct two 'if' conditionals, Markus Armbruster, 2021/08/31
- [PATCH 10/12] tests/qapi-schema: Hide OrderedDict in test output, Markus Armbruster, 2021/08/31
- [PATCH 11/12] qapi: Tweak error messages for missing / conflicting meta-type,
Markus Armbruster <=
- [PATCH 12/12] qapi: Tweak error messages for unknown / conflicting 'if' keys, Markus Armbruster, 2021/08/31
- [PATCH 09/12] qapi: Use re.fullmatch() where appropriate, Markus Armbruster, 2021/08/31
- Re: [PATCH 00/12] qapi: Fixes and cleanups for recent work (mostly), Marc-André Lureau, 2021/08/31