Skip to content

Commit

Permalink
utils/templates: Use ipalib_errors.NotFound instead of Exception
Browse files Browse the repository at this point in the history
Modify the plugin templates so that the code generated does not hide
errors when querying IPA wih *_show command by handlig only the exeption
where an object is not found.
  • Loading branch information
rjeffman committed Dec 3, 2024
1 parent 1c4b50f commit 5abb515
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions utils/templates/ipamodule+member.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ RETURN = """

from ansible.module_utils.ansible_freeipa_module import \
IPAAnsibleModule, compare_args_ipa, gen_add_del_lists, gen_add_list, \
gen_intersection_list
gen_intersection_list, ipalib_errors
from ansible.module_utils import six

if six.PY3:
Expand All @@ -124,7 +124,7 @@ def find_$name(module, name):
"""Find if a $name with the given name already exist."""
try:
_result = module.ipa_command("$name_show", name, {"all": True})
except Exception: # pylint: disable=broad-except
except ipalib_errors.NotFound:
# An exception is raised if $name name is not found.
return None
return _result["result"]
Expand Down
4 changes: 2 additions & 2 deletions utils/templates/ipamodule.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ RETURN = """


from ansible.module_utils.ansible_freeipa_module import \
IPAAnsibleModule, compare_args_ipa
IPAAnsibleModule, compare_args_ipa, ipalib_errors
from ansible.module_utils import six

if six.PY3:
Expand All @@ -100,7 +100,7 @@ def find_$name(module, name):
"""Find if a $name with the given name already exist."""
try:
_result = module.ipa_command("$name_show", name, {"all": True})
except Exception: # pylint: disable=broad-except
except ipalib_errors.NotFound:
# An exception is raised if $name name is not found.
return None
return _result["result"]
Expand Down

0 comments on commit 5abb515

Please sign in to comment.