Improve exception handling. (#121)

This commit is contained in:
Felix Fontein
2021-04-08 08:00:01 +02:00
committed by GitHub
parent ff503d9bd7
commit a3b9648233
24 changed files with 168 additions and 98 deletions
+7 -3
View File
@@ -165,6 +165,8 @@ images:
import traceback
from ansible.module_utils._text import to_native
try:
from docker import utils
from docker.errors import DockerException, NotFound
@@ -235,7 +237,7 @@ class ImageManager(DockerBaseClass):
except NotFound:
pass
except Exception as exc:
self.fail("Error inspecting image %s - %s" % (image['Id'], str(exc)))
self.fail("Error inspecting image %s - %s" % (image['Id'], to_native(exc)))
results.append(inspection)
return results
@@ -260,9 +262,11 @@ def main():
ImageManager(client, results)
client.module.exit_json(**results)
except DockerException as e:
client.fail('An unexpected docker error occurred: {0}'.format(e), exception=traceback.format_exc())
client.fail('An unexpected docker error occurred: {0}'.format(to_native(e)), exception=traceback.format_exc())
except RequestException as e:
client.fail('An unexpected requests error occurred when docker-py tried to talk to the docker daemon: {0}'.format(e), exception=traceback.format_exc())
client.fail(
'An unexpected requests error occurred when docker-py tried to talk to the docker daemon: {0}'.format(to_native(e)),
exception=traceback.format_exc())
if __name__ == '__main__':