[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 09/19] qapi/expr.py: Check type of 'data' member
From: |
John Snow |
Subject: |
[PATCH v4 09/19] qapi/expr.py: Check type of 'data' member |
Date: |
Thu, 25 Mar 2021 02:03:46 -0400 |
We don't actually check, so the user can get some unpleasant stacktraces.
Formalize it.
Signed-off-by: John Snow <jsnow@redhat.com>
---
scripts/qapi/expr.py | 7 +++++++
tests/qapi-schema/alternate-invalid-data-type.err | 2 ++
tests/qapi-schema/union-invalid-data-type.err | 2 ++
3 files changed, 11 insertions(+)
diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py
index 73e7d8cb0d..ca5ab7bfda 100644
--- a/scripts/qapi/expr.py
+++ b/scripts/qapi/expr.py
@@ -281,6 +281,9 @@ def check_union(expr, info):
raise QAPISemError(info, "'discriminator' requires 'base'")
check_name_is_str(discriminator, info, "'discriminator'")
+ if not isinstance(members, dict):
+ raise QAPISemError(info, "'data' must be an object")
+
for (key, value) in members.items():
source = "'data' member '%s'" % key
if discriminator is None:
@@ -296,6 +299,10 @@ def check_alternate(expr, info):
if not members:
raise QAPISemError(info, "'data' must not be empty")
+
+ if not isinstance(members, dict):
+ raise QAPISemError(info, "'data' must be an object")
+
for (key, value) in members.items():
source = "'data' member '%s'" % key
check_name_lower(key, info, source)
diff --git a/tests/qapi-schema/alternate-invalid-data-type.err
b/tests/qapi-schema/alternate-invalid-data-type.err
index e69de29bb2..c7301ccb00 100644
--- a/tests/qapi-schema/alternate-invalid-data-type.err
+++ b/tests/qapi-schema/alternate-invalid-data-type.err
@@ -0,0 +1,2 @@
+alternate-invalid-data-type.json: In alternate 'Alt':
+alternate-invalid-data-type.json:2: 'data' must be an object
diff --git a/tests/qapi-schema/union-invalid-data-type.err
b/tests/qapi-schema/union-invalid-data-type.err
index e69de29bb2..b71c3400c5 100644
--- a/tests/qapi-schema/union-invalid-data-type.err
+++ b/tests/qapi-schema/union-invalid-data-type.err
@@ -0,0 +1,2 @@
+union-invalid-data-type.json: In union 'TestUnion':
+union-invalid-data-type.json:9: 'data' must be an object
--
2.30.2
- Re: [PATCH v4 02/19] flake8: Enforce shorter line length for comments and docstrings, (continued)
- [PATCH v4 03/19] qapi/expr.py: Remove 'info' argument from nested check_if_str, John Snow, 2021/03/25
- [PATCH v4 04/19] qapi/expr.py: Check for dict instead of OrderedDict, John Snow, 2021/03/25
- [PATCH v4 07/19] qapi/expr.py: move string check upwards in check_type, John Snow, 2021/03/25
- [PATCH v4 05/19] qapi/expr.py: constrain incoming expression types, John Snow, 2021/03/25
- [PATCH v4 06/19] qapi/expr.py: Add assertion for union type 'check_dict', John Snow, 2021/03/25
- [PATCH v4 08/19] qapi: add tests for invalid 'data' field type, John Snow, 2021/03/25
- [PATCH v4 09/19] qapi/expr.py: Check type of 'data' member,
John Snow <=
- [PATCH v4 10/19] qapi/expr.py: Add casts in a few select cases, John Snow, 2021/03/25
- [PATCH v4 12/19] qapi/expr.py: add type hint annotations, John Snow, 2021/03/25
- [PATCH v4 13/19] qapi/expr.py: Consolidate check_if_str calls in check_if, John Snow, 2021/03/25
- [PATCH v4 15/19] qapi/expr.py: enable pylint checks, John Snow, 2021/03/25