1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Try to be more helpful when JSON gives up (#45600)

* Try to be more helpful when JSON gives up
This commit is contained in:
Nathaniel Case 2018-09-24 09:09:17 -04:00 committed by GitHub
parent 7caf70db42
commit 03d8fa05b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -142,6 +142,27 @@ class Connection(object):
try:
data = json.dumps(req)
except TypeError as exc:
data = req.get('params')
if isinstance(data, dict):
data = data.get('var_options', {})
for key, value in iteritems(data):
try:
dummy = json.dumps(value)
except TypeError:
raise ConnectionError(
"Failed to encode some variables as JSON for communication with ansible-connection. "
"Please open an issue and mention that the culprit is most likely '%s'" % key
)
raise ConnectionError(
"Failed to encode some variables as JSON for communication with ansible-connection. "
"The original exception was: %s" % to_text(exc)
)
try:
out = self.send(data)
response = json.loads(out)