Improve error handling. (#1035)

This commit is contained in:
Felix Fontein 2025-01-31 19:39:08 +01:00 committed by GitHub
parent 8bae4e9c6d
commit 511cfe52ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View File

@ -0,0 +1,3 @@
bugfixes:
- "vendored Docker SDK for Python - do not assume that ``KeyError`` is always for ``ApiVersion`` when querying version fails
(https://github.com/ansible-collections/community.docker/issues/1033, https://github.com/ansible-collections/community.docker/pull/1034)."

View File

@ -202,7 +202,14 @@ class APIClient(
def _retrieve_server_version(self): def _retrieve_server_version(self):
try: try:
return self.version(api_version=False)["ApiVersion"] version_result = self.version(api_version=False)
except Exception as e:
raise DockerException(
'Error while fetching server API version: {0}'.format(e)
)
try:
return version_result["ApiVersion"]
except KeyError: except KeyError:
raise DockerException( raise DockerException(
'Invalid response from docker daemon: key "ApiVersion"' 'Invalid response from docker daemon: key "ApiVersion"'
@ -210,7 +217,7 @@ class APIClient(
) )
except Exception as e: except Exception as e:
raise DockerException( raise DockerException(
'Error while fetching server API version: {0}'.format(e) 'Error while fetching server API version: {0}. Response seems to be broken.'.format(e)
) )
def _set_request_timeout(self, kwargs): def _set_request_timeout(self, kwargs):