From 3448fcabc539fb2d3351c20a5b82c3558d037c75 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Mon, 14 Nov 2022 11:45:34 -0500 Subject: [PATCH] file lookup now works with general lookup error framework (#79339) * file lookup now works with general lookup error framework --- changelogs/fragments/file_lookup_errors.yml | 2 ++ lib/ansible/plugins/lookup/file.py | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/file_lookup_errors.yml diff --git a/changelogs/fragments/file_lookup_errors.yml b/changelogs/fragments/file_lookup_errors.yml new file mode 100644 index 00000000000..5f5cfce66af --- /dev/null +++ b/changelogs/fragments/file_lookup_errors.yml @@ -0,0 +1,2 @@ +bugfixes: + - file lookup now plays nice with generic lookup ``errors`` option. diff --git a/lib/ansible/plugins/lookup/file.py b/lib/ansible/plugins/lookup/file.py index 9657536d73a..b4b883fe256 100644 --- a/lib/ansible/plugins/lookup/file.py +++ b/lib/ansible/plugins/lookup/file.py @@ -50,7 +50,7 @@ RETURN = """ elements: str """ -from ansible.errors import AnsibleError, AnsibleOptionsError +from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleLookupError from ansible.plugins.lookup import LookupBase from ansible.module_utils._text import to_text from ansible.utils.display import Display @@ -81,8 +81,8 @@ class LookupModule(LookupBase): ret.append(contents) else: # TODO: only add search info if abs path? - raise AnsibleError("file not found, use -vvvvv to see paths searched") + raise AnsibleOptionsError("file not found, use -vvvvv to see paths searched") except AnsibleError as e: - raise AnsibleOptionsError("The 'file' lookup had an issue accessing the file '%s'" % term, orig_exc=e) + raise AnsibleLookupError("The 'file' lookup had an issue accessing the file '%s'" % term, orig_exc=e) return ret