Skip to content

Commit

Permalink
Improve error handling. (#1035)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein authored Jan 31, 2025
1 parent 8bae4e9 commit 511cfe5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/1034-error-msg.yml
Original file line number Diff line number Diff line change
@@ -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)."
11 changes: 9 additions & 2 deletions plugins/module_utils/_api/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,22 @@ def __init__(self, base_url=None, version=None,

def _retrieve_server_version(self):
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:
raise DockerException(
'Invalid response from docker daemon: key "ApiVersion"'
' is missing.'
)
except Exception as e:
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):
Expand Down

0 comments on commit 511cfe5

Please sign in to comment.