1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-06-11 10:35:34 +00:00

[PR #12140/48db8630 backport][stable-13] filetree lookup: handle invalid exclude regex with AnsibleError (#12184)

filetree lookup: handle invalid exclude regex with AnsibleError (#12140)

* filetree lookup - handle invalid exclude regex with AnsibleError Wrap re.compile() for the exclude option so invalid regular expressions produce a clear AnsibleError instead of an uncaught re.error traceback.

* add changelog fragment

* add changelog fragment

* Fix changelog fragment line endings (LF)



* Used AnsibleLookupError instead of AnsibleError

* Update changelogs/fragments/12140-filetree-exclude-regex-error.yml



* Used AnsibleLookupError instead of AnsibleError

* Updated changelog format

---------



(cherry picked from commit 48db863096)

Co-authored-by: Santosh Mahale <santoshmahale7676@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
patchback[bot] 2026-06-04 06:28:33 +02:00 committed by GitHub
parent 06f2bf2aee
commit 828eef091e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- filetree lookup plugin - raise ``AnsibleLookupError`` when the ``exclude`` option contains an invalid regular expression instead of an uncaught ``re.error`` (https://github.com/ansible-collections/community.general/pull/12140).

View file

@ -143,6 +143,7 @@ try:
except ImportError:
pass
from ansible.errors import AnsibleLookupError
from ansible.module_utils.common.text.converters import to_native, to_text
from ansible.plugins.lookup import LookupBase
from ansible.utils.display import Display
@ -227,7 +228,13 @@ class LookupModule(LookupBase):
# Regular expression for exclude
exclude = self.get_option("exclude")
exclude_pattern = re.compile(exclude) if exclude else None
if exclude:
try:
exclude_pattern = re.compile(exclude)
except re.error as e:
raise AnsibleLookupError(f"Invalid exclude regular expression {exclude!r}: {e}") from e
else:
exclude_pattern = None
ret = []
for term in terms: