1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-05 03:37:01 +00:00

[PR #11095/2b4333a0 backport][stable-12] Use raise from in plugins (#11129)

Use raise from in plugins (#11095)

* Use raise from.

* Add changelog fragment.

(cherry picked from commit 2b4333a033)

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
patchback[bot] 2025-11-12 21:00:39 +01:00 committed by GitHub
parent cddb570e0e
commit cc93dab0fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
46 changed files with 218 additions and 165 deletions

View file

@ -78,9 +78,9 @@ def _keys_filter_target_str(target, matching_parameter):
r = target[0]
try:
tt = re.compile(r)
except re.error:
except re.error as e:
msg = "The target must be a valid regex if matching_parameter=regex. target is %s"
raise AnsibleFilterError(msg % r)
raise AnsibleFilterError(msg % r) from e
elif isinstance(target, str):
tt = (target,)
else:
@ -129,12 +129,12 @@ def _keys_filter_target_dict(target, matching_parameter):
try:
tr = map(re.compile, before)
tz = list(zip(tr, after))
except re.error:
except re.error as e:
msg = (
"The attributes before must be valid regex if matching_parameter=regex."
" Not all items are valid regex in: %s"
)
raise AnsibleFilterError(msg % before)
raise AnsibleFilterError(msg % before) from e
else:
tz = list(zip(before, after))