qapi: Tweak error messages for missing / conflicting meta-type

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20210831123809.1107782-12-armbru@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Markus Armbruster 2021-08-31 14:38:08 +02:00
parent 9c629fa834
commit 6dcf03719a
3 changed files with 11 additions and 18 deletions

View File

@ -630,20 +630,15 @@ def check_exprs(exprs: List[_JSONObject]) -> List[_JSONObject]:
if 'include' in expr: if 'include' in expr:
continue continue
if 'enum' in expr: metas = expr.keys() & {'enum', 'struct', 'union', 'alternate',
meta = 'enum' 'command', 'event'}
elif 'union' in expr: if len(metas) != 1:
meta = 'union' raise QAPISemError(
elif 'alternate' in expr: info,
meta = 'alternate' "expression must have exactly one key"
elif 'struct' in expr: " 'enum', 'struct', 'union', 'alternate',"
meta = 'struct' " 'command', 'event'")
elif 'command' in expr: meta = metas.pop()
meta = 'command'
elif 'event' in expr:
meta = 'event'
else:
raise QAPISemError(info, "expression is missing metatype")
check_name_is_str(expr[meta], info, "'%s'" % meta) check_name_is_str(expr[meta], info, "'%s'" % meta)
name = cast(str, expr[meta]) name = cast(str, expr[meta])

View File

@ -1,3 +1 @@
double-type.json: In struct 'Bar': double-type.json:2: expression must have exactly one key 'enum', 'struct', 'union', 'alternate', 'command', 'event'
double-type.json:2: struct has unknown key 'command'
Valid keys are 'base', 'data', 'features', 'if', 'struct'.

View File

@ -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'