qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

qapi: improve reporting of unknown or missing keys

Report the set of missing or unknown keys. And give a hint about the
accepted keys.

The error message for multiple meta type members (visible in
tests/qapi-schema/double-type.err) is not improved.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20181213123724.4866-6-marcandre.lureau@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>

authored by

Marc-André Lureau and committed by
Markus Armbruster
7e80d480 563bd35d

+19 -9
+14 -7
scripts/qapi/common.py
··· 874 874 875 875 876 876 def check_known_keys(info, source, keys, required, optional): 877 - for key in keys: 878 - if key not in required and key not in optional: 879 - raise QAPISemError(info, "Unknown key '%s' in %s" % (key, source)) 877 + 878 + def pprint(elems): 879 + return ', '.join("'" + e + "'" for e in sorted(elems)) 880 880 881 - for key in required: 882 - if key not in keys: 883 - raise QAPISemError(info, "Key '%s' is missing from %s" 884 - % (key, source)) 881 + missing = set(required) - set(keys) 882 + if missing: 883 + raise QAPISemError(info, "Key%s %s %s missing from %s" 884 + % ('s' if len(missing) > 1 else '', pprint(missing), 885 + 'are' if len(missing) > 1 else 'is', source)) 886 + allowed = set(required + optional) 887 + unknown = set(keys) - allowed 888 + if unknown: 889 + raise QAPISemError(info, "Unknown key%s %s in %s\nValid keys are %s." 890 + % ('s' if len(unknown) > 1 else '', pprint(unknown), 891 + source, pprint(allowed))) 885 892 886 893 887 894 def check_keys(expr_elem, meta, required, optional=[]):
+1
tests/qapi-schema/alternate-base.err
··· 1 1 tests/qapi-schema/alternate-base.json:4: Unknown key 'base' in alternate 'Alt' 2 + Valid keys are 'alternate', 'data', 'if'.
+1
tests/qapi-schema/double-type.err
··· 1 1 tests/qapi-schema/double-type.json:2: Unknown key 'command' in struct 'bar' 2 + Valid keys are 'base', 'data', 'if', 'struct'.
+2 -1
tests/qapi-schema/unknown-expr-key.err
··· 1 - tests/qapi-schema/unknown-expr-key.json:2: Unknown key 'bogus' in struct 'bar' 1 + tests/qapi-schema/unknown-expr-key.json:2: Unknown keys 'bogus', 'phony' in struct 'bar' 2 + Valid keys are 'base', 'data', 'if', 'struct'.
+1 -1
tests/qapi-schema/unknown-expr-key.json
··· 1 1 # we reject an expression with unknown top-level keys 2 - { 'struct': 'bar', 'data': { 'string': 'str'}, 'bogus': { } } 2 + { 'struct': 'bar', 'data': { 'string': 'str'}, 'bogus': { }, 'phony': { } }