summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGaudenz Steinlin <gaudenz@users.noreply.github.com>2022-11-16 19:36:36 +0100
committerGitHub <noreply@github.com>2022-11-16 12:36:36 -0600
commit5f6537b644a8934de8a7b3ea603f134f23dc72fd (patch)
tree02ac33fad43ccc32b87b39a17aba24c123a5706a
parentfd63b2f306da2323b6a285684bcbc98606905443 (diff)
downloadansible-5f6537b644a8934de8a7b3ea603f134f23dc72fd.tar.gz
file lookup now works with general lookup error framework (#79339) (#79388)
* file lookup now works with general lookup error framework (cherry picked from commit 3448fcabc539fb2d3351c20a5b82c3558d037c75) Co-authored-by: Brian Coca <bcoca@users.noreply.github.com>
-rw-r--r--changelogs/fragments/file_lookup_errors.yml2
-rw-r--r--lib/ansible/plugins/lookup/file.py6
2 files changed, 5 insertions, 3 deletions
diff --git a/changelogs/fragments/file_lookup_errors.yml b/changelogs/fragments/file_lookup_errors.yml
new file mode 100644
index 0000000000..5f5cfce66a
--- /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 9657536d73..b4b883fe25 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