Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file lookup now works with general lookup error framework #79339

Merged
merged 3 commits into from Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/file_lookup_errors.yml
@@ -0,0 +1,2 @@
bugfixes:
- file lookup now plays nice with generic lookup ``errors`` option.
6 changes: 3 additions & 3 deletions lib/ansible/plugins/lookup/file.py
Expand Up @@ -50,7 +50,7 @@
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
Expand Down Expand Up @@ -81,8 +81,8 @@ def run(self, terms, variables=None, **kwargs):
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