mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
Handle errors in jmespath in json_query better (#22109)
* Handle errors in jmespath in json_query better Catch any exceptions raised from jmespath and raise an AnsibleFilterError instead. Avoid a traceback. Fixes #20379 * pep8
This commit is contained in:
@@ -18,9 +18,7 @@
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
from ansible.utils.listify import listify_lookup_plugin_terms
|
||||
from ansible.errors import AnsibleError, AnsibleFilterError
|
||||
|
||||
try:
|
||||
import jmespath
|
||||
@@ -37,7 +35,13 @@ def json_query(data, expr):
|
||||
raise AnsibleError('You need to install "jmespath" prior to running '
|
||||
'json_query filter')
|
||||
|
||||
return jmespath.search(expr, data)
|
||||
try:
|
||||
return jmespath.search(expr, data)
|
||||
except jmespath.exceptions.JMESPathError as e:
|
||||
raise AnsibleFilterError('JMESPathError in json_query filter plugin:\n%s' % e)
|
||||
except Exception as e:
|
||||
# For older jmespath, we can get ValueError and TypeError without much info.
|
||||
raise AnsibleFilterError('Error in jmespath.search in json_query filter plugin:\n%s' % e)
|
||||
|
||||
|
||||
class FilterModule(object):
|
||||
|
||||
Reference in New Issue
Block a user