[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v4 09/19] qapi/expr.py: Check type of 'data' member
From: |
Markus Armbruster |
Subject: |
Re: [PATCH v4 09/19] qapi/expr.py: Check type of 'data' member |
Date: |
Thu, 25 Mar 2021 15:26:12 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) |
Suggest
qapi/expr.py: Check type of union and alternate 'data' member
John Snow <jsnow@redhat.com> writes:
> We don't actually check, so the user can get some unpleasant stacktraces.
Let's point to the new tests here.
> Formalize it.
Huh?
> 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
- [PATCH v4 03/19] qapi/expr.py: Remove 'info' argument from nested check_if_str, (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, 2021/03/25
- Re: [PATCH v4 09/19] qapi/expr.py: Check type of 'data' member,
Markus Armbruster <=
- [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
- [PATCH v4 17/19] qapi/expr.py: Use tuples instead of lists for static data, John Snow, 2021/03/25