Skip to content

Commit

Permalink
qapi: Fix errors for non-string, non-dictionary members
Browse files Browse the repository at this point in the history
Fixes the errors demonstrated by the previous commit.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
  • Loading branch information
Markus Armbruster committed Sep 4, 2015
1 parent 10689e3 commit c6b71e5
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 10 deletions.
10 changes: 6 additions & 4 deletions scripts/qapi.py
Expand Up @@ -462,13 +462,15 @@ def check_type(expr_info, source, value, allow_array = False,
% (source, all_names[value], orig_value))
return

# value is a dictionary, check that each member is okay
if not isinstance(value, OrderedDict):
raise QAPIExprError(expr_info,
"%s should be a dictionary" % source)
if not allow_dict:
raise QAPIExprError(expr_info,
"%s should be a type name" % source)

if not isinstance(value, OrderedDict):
raise QAPIExprError(expr_info,
"%s should be a dictionary or type name" % source)

# value is a dictionary, check that each member is okay
for (key, arg) in value.items():
check_name(expr_info, "Member of %s" % source, key,
allow_optional=allow_optional)
Expand Down
2 changes: 1 addition & 1 deletion tests/qapi-schema/args-invalid.err
@@ -1 +1 @@
tests/qapi-schema/args-invalid.json:2: 'data' for command 'foo' should be a dictionary
tests/qapi-schema/args-invalid.json:1: 'data' for command 'foo' should be a dictionary or type name
1 change: 0 additions & 1 deletion tests/qapi-schema/args-invalid.json
@@ -1,3 +1,2 @@
# FIXME error "should be a dictionary" is misleading, type name is also fine
{ 'command': 'foo',
'data': false }
2 changes: 1 addition & 1 deletion tests/qapi-schema/struct-data-invalid.err
@@ -1 +1 @@
tests/qapi-schema/struct-data-invalid.json:2: 'data' for struct 'foo' should be a dictionary
tests/qapi-schema/struct-data-invalid.json:1: 'data' for struct 'foo' should be a dictionary or type name
1 change: 0 additions & 1 deletion tests/qapi-schema/struct-data-invalid.json
@@ -1,3 +1,2 @@
# FIXME error "should be a dictionary" is misleading, type name is also fine
{ 'struct': 'foo',
'data': false }
2 changes: 1 addition & 1 deletion tests/qapi-schema/struct-member-invalid.err
@@ -1 +1 @@
tests/qapi-schema/struct-member-invalid.json:2: Member 'a' of 'data' for struct 'foo' should be a dictionary
tests/qapi-schema/struct-member-invalid.json:1: Member 'a' of 'data' for struct 'foo' should be a type name
1 change: 0 additions & 1 deletion tests/qapi-schema/struct-member-invalid.json
@@ -1,3 +1,2 @@
# FIXME error message "should be a dictionary" is wrong, must be type name
{ 'struct': 'foo',
'data': { 'a': false } }

0 comments on commit c6b71e5

Please sign in to comment.