Skip to content

Commit

Permalink
Catch exceptions when no JSON output in podman_image (#680)
Browse files Browse the repository at this point in the history
Fix #676
Signed-off-by: Sagi Shnaidman <[email protected]>
  • Loading branch information
sshnaidm authored Nov 30, 2023
1 parent 2d00639 commit c3b38b5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions plugins/modules/podman_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,10 @@ def find_image(self, image_name=None):
image_name = self.image_name
args = ['image', 'ls', image_name, '--format', 'json']
rc, images, err = self._run(args, ignore_errors=True)
images = json.loads(images)
try:
images = json.loads(images)
except json.decoder.JSONDecodeError:
self.module.fail_json(msg='Failed to parse JSON output from podman image ls: {out}'.format(out=images))
if len(images) == 0:
# Let's find out if image exists
rc, out, err = self._run(['image', 'exists', image_name], ignore_errors=True)
Expand Down Expand Up @@ -577,7 +580,10 @@ def inspect_image(self, image_name=None):
image_name = self.image_name
args = ['inspect', image_name, '--format', 'json']
rc, image_data, err = self._run(args)
image_data = json.loads(image_data)
try:
image_data = json.loads(image_data)
except json.decoder.JSONDecodeError:
self.module.fail_json(msg='Failed to parse JSON output from podman inspect: {out}'.format(out=image_data))
if len(image_data) > 0:
return image_data
else:
Expand Down

0 comments on commit c3b38b5

Please sign in to comment.