From cf89ca8a03a8a84302ad27cb1fc7aa9120b743ca Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Fri, 10 Jul 2020 18:49:57 -0400 Subject: Make filter type errors 'loop friendly' (#70417) - ensure we preserve the typeerror part of the exception so loop defereed error handling can postpone those caused by undefined variables until the when check is done. - fix tests to comply with the 'new normal' - human_to_bytes and others can issue TypeError not only on 'non string' but also bad string that is not convertable. Co-authored-by: Sloane Hertel Co-authored-by: Sloane Hertel --- .../filter_core/handle_undefined_type_errors.yml | 29 ++++++++++++++++++++++ test/integration/targets/filter_core/runme.sh | 1 + .../integration/targets/filter_core/tasks/main.yml | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/integration/targets/filter_core/handle_undefined_type_errors.yml (limited to 'test/integration/targets/filter_core') diff --git a/test/integration/targets/filter_core/handle_undefined_type_errors.yml b/test/integration/targets/filter_core/handle_undefined_type_errors.yml new file mode 100644 index 0000000000..70628809a4 --- /dev/null +++ b/test/integration/targets/filter_core/handle_undefined_type_errors.yml @@ -0,0 +1,29 @@ +- hosts: localhost + gather_facts: false + tasks: + - debug: msg={{item}} + with_dict: '{{myundef}}' + when: + - myundef is defined + register: shouldskip + + - name: check if skipped + assert: + that: + - shouldskip is skipped + + - debug: msg={{item}} + loop: '{{myundef|dict2items}}' + when: + - myundef is defined + + - debug: msg={{item}} + with_dict: '{{myundef}}' + register: notskipped + ignore_errors: true + + - name: check it failed + assert: + that: + - notskipped is not skipped + - notskipped is failed diff --git a/test/integration/targets/filter_core/runme.sh b/test/integration/targets/filter_core/runme.sh index ac4361f3a4..c055603b0f 100755 --- a/test/integration/targets/filter_core/runme.sh +++ b/test/integration/targets/filter_core/runme.sh @@ -3,3 +3,4 @@ set -eux ANSIBLE_ROLES_PATH=../ ansible-playbook runme.yml "$@" +ANSIBLE_ROLES_PATH=../ ansible-playbook handle_undefined_type_errors.yml "$@" diff --git a/test/integration/targets/filter_core/tasks/main.yml b/test/integration/targets/filter_core/tasks/main.yml index 4f7517004b..3b5cba39ee 100644 --- a/test/integration/targets/filter_core/tasks/main.yml +++ b/test/integration/targets/filter_core/tasks/main.yml @@ -528,7 +528,7 @@ - subelements_1 is failed - 'subelements_1.msg == "obj must be a list of dicts or a nested dict"' - subelements_2 is failed - - 'subelements_2.msg == "subelements must be a list or a string"' + - '"subelements must be a list or a string" in subelements_2.msg' - 'subelements_demo|subelements("does not compute", skip_missing=True) == []' - subelements_3 is failed - '"could not find" in subelements_3.msg' -- cgit v1.2.1