mirror of
https://github.com/ansible-collections/community.docker.git
synced 2025-12-15 19:42:06 +00:00
Improve JSON parsing error handling. (#1221)
(cherry picked from commit 6ab8cc0d82)
This commit is contained in:
parent
091e393e6d
commit
4399cb5a35
3
changelogs/fragments/1221-cli-json-errors.yml
Normal file
3
changelogs/fragments/1221-cli-json-errors.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
bugfixes:
|
||||||
|
- "CLI-based modules - when parsing JSON output fails, also provide standard error output. Also provide information on the command and its result in machine-readable way
|
||||||
|
(https://github.com/ansible-collections/community.docker/issues/1216, https://github.com/ansible-collections/community.docker/pull/1221)."
|
||||||
@ -133,11 +133,18 @@ class AnsibleDockerClientBase(object):
|
|||||||
try:
|
try:
|
||||||
data = json.loads(stdout)
|
data = json.loads(stdout)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self.fail('Error while parsing JSON output of {cmd}: {exc}\nJSON output: {stdout}'.format(
|
self.fail(
|
||||||
|
'Error while parsing JSON output of {cmd}: {exc}\nJSON output: {stdout}\n\nError output:\n{stderr}'.format(
|
||||||
|
cmd=self._compose_cmd_str(args),
|
||||||
|
exc=to_native(exc),
|
||||||
|
stdout=to_native(stdout),
|
||||||
|
stderr=to_native(stderr),
|
||||||
|
),
|
||||||
cmd=self._compose_cmd_str(args),
|
cmd=self._compose_cmd_str(args),
|
||||||
exc=to_native(exc),
|
rc=rc,
|
||||||
stdout=to_native(stdout),
|
stdout=to_native(stdout),
|
||||||
))
|
stderr=to_native(stderr),
|
||||||
|
)
|
||||||
return rc, data, stderr
|
return rc, data, stderr
|
||||||
|
|
||||||
# def call_cli_json_stream(self, *args, check_rc=False, data=None, cwd=None, environ_update=None, warn_on_stderr=False):
|
# def call_cli_json_stream(self, *args, check_rc=False, data=None, cwd=None, environ_update=None, warn_on_stderr=False):
|
||||||
@ -153,11 +160,18 @@ class AnsibleDockerClientBase(object):
|
|||||||
if line.startswith(b'{'):
|
if line.startswith(b'{'):
|
||||||
result.append(json.loads(line))
|
result.append(json.loads(line))
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self.fail('Error while parsing JSON output of {cmd}: {exc}\nJSON output: {stdout}'.format(
|
self.fail(
|
||||||
|
'Error while parsing JSON output of {cmd}: {exc}\nJSON output: {stdout}\n\nError output:\n{stderr}'.format(
|
||||||
|
cmd=self._compose_cmd_str(args),
|
||||||
|
exc=to_native(exc),
|
||||||
|
stdout=to_native(stdout),
|
||||||
|
stderr=to_native(stderr),
|
||||||
|
),
|
||||||
cmd=self._compose_cmd_str(args),
|
cmd=self._compose_cmd_str(args),
|
||||||
exc=to_native(exc),
|
rc=rc,
|
||||||
stdout=to_native(stdout),
|
stdout=to_native(stdout),
|
||||||
))
|
stderr=to_native(stderr),
|
||||||
|
)
|
||||||
return rc, result, stderr
|
return rc, result, stderr
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user