mirror of
https://github.com/ansible-collections/community.docker.git
synced 2025-12-15 19:42:06 +00:00
Improve error message on import errors. (#188)
This commit is contained in:
parent
46bffd2f36
commit
930f9d1bcd
2
changelogs/fragments/188-improve-import-errors.yml
Normal file
2
changelogs/fragments/188-improve-import-errors.yml
Normal file
@ -0,0 +1,2 @@
|
||||
minor_changes:
|
||||
- "docker_* modules - include ``ImportError`` traceback when reporting that Docker SDK for Python could not be found (https://github.com/ansible-collections/community.docker/pull/188)."
|
||||
@ -10,6 +10,7 @@ import os
|
||||
import platform
|
||||
import re
|
||||
import sys
|
||||
import traceback
|
||||
from datetime import timedelta
|
||||
from distutils.version import LooseVersion
|
||||
|
||||
@ -25,6 +26,7 @@ HAS_DOCKER_PY = True
|
||||
HAS_DOCKER_PY_2 = False
|
||||
HAS_DOCKER_PY_3 = False
|
||||
HAS_DOCKER_ERROR = None
|
||||
HAS_DOCKER_TRACEBACK = None
|
||||
|
||||
try:
|
||||
from requests.exceptions import SSLError
|
||||
@ -44,10 +46,11 @@ try:
|
||||
|
||||
except ImportError as exc:
|
||||
HAS_DOCKER_ERROR = str(exc)
|
||||
HAS_DOCKER_TRACEBACK = traceback.format_exc()
|
||||
HAS_DOCKER_PY = False
|
||||
|
||||
|
||||
# The next 2 imports ``docker.models`` and ``docker.ssladapter`` are used
|
||||
# The next two imports ``docker.models`` and ``docker.ssladapter`` are used
|
||||
# to ensure the user does not have both ``docker`` and ``docker-py`` modules
|
||||
# installed, as they utilize the same namespace are are incompatible
|
||||
try:
|
||||
@ -288,7 +291,7 @@ class AnsibleDockerClientBase(Client):
|
||||
"docker before 5.0.0 (Python 2.7) or docker-py (Python 2.6)")
|
||||
msg = msg + ", for example via `pip install docker` (Python >= 3.6) or `pip install docker==4.4.4` (Python 2.7) " \
|
||||
+ "or `pip install docker-py` (Python 2.6). The error was: %s"
|
||||
self.fail(msg % HAS_DOCKER_ERROR)
|
||||
self.fail(msg % HAS_DOCKER_ERROR, exception=HAS_DOCKER_TRACEBACK)
|
||||
|
||||
if self.docker_py_version < LooseVersion(min_docker_version):
|
||||
msg = "Error: Docker SDK for Python version is %s (%s's Python %s). Minimum version required is %s."
|
||||
|
||||
Loading…
Reference in New Issue
Block a user