Skip to content

Commit 6dcf037

Browse files
author
Markus Armbruster
committed
qapi: Tweak error messages for missing / conflicting meta-type
Signed-off-by: Markus Armbruster <[email protected]> Message-Id: <[email protected]> Reviewed-by: Marc-André Lureau <[email protected]>
1 parent 9c629fa commit 6dcf037

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

scripts/qapi/expr.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -630,20 +630,15 @@ def check_exprs(exprs: List[_JSONObject]) -> List[_JSONObject]:
630630
if 'include' in expr:
631631
continue
632632

633-
if 'enum' in expr:
634-
meta = 'enum'
635-
elif 'union' in expr:
636-
meta = 'union'
637-
elif 'alternate' in expr:
638-
meta = 'alternate'
639-
elif 'struct' in expr:
640-
meta = 'struct'
641-
elif 'command' in expr:
642-
meta = 'command'
643-
elif 'event' in expr:
644-
meta = 'event'
645-
else:
646-
raise QAPISemError(info, "expression is missing metatype")
633+
metas = expr.keys() & {'enum', 'struct', 'union', 'alternate',
634+
'command', 'event'}
635+
if len(metas) != 1:
636+
raise QAPISemError(
637+
info,
638+
"expression must have exactly one key"
639+
" 'enum', 'struct', 'union', 'alternate',"
640+
" 'command', 'event'")
641+
meta = metas.pop()
647642

648643
check_name_is_str(expr[meta], info, "'%s'" % meta)
649644
name = cast(str, expr[meta])

tests/qapi-schema/double-type.err

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
double-type.json: In struct 'Bar':
2-
double-type.json:2: struct has unknown key 'command'
3-
Valid keys are 'base', 'data', 'features', 'if', 'struct'.
1+
double-type.json:2: expression must have exactly one key 'enum', 'struct', 'union', 'alternate', 'command', 'event'

tests/qapi-schema/missing-type.err

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
missing-type.json:2: expression is missing metatype
1+
missing-type.json:2: expression must have exactly one key 'enum', 'struct', 'union', 'alternate', 'command', 'event'

0 commit comments

Comments
 (0)