Skip to content

Commit

Permalink
Fix error handling. (#546)
Browse files Browse the repository at this point in the history
(cherry picked from commit 1809119)
  • Loading branch information
felixfontein authored and patchback[bot] committed Jan 5, 2023
1 parent 3edb792 commit d33d03b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/546-conflict-error.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- "docker_api connection plugin - fix error handling when 409 Conflict is returned by the Docker daemon in case of a stopped container (https://github.com/ansible-collections/community.docker/pull/546)."
- "docker_container_exec - fix error handling when 409 Conflict is returned by the Docker daemon in case of a stopped container (https://github.com/ansible-collections/community.docker/pull/546)."
2 changes: 1 addition & 1 deletion plugins/connection/docker_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _call_client(self, callable, not_found_can_be_resource=False):
else:
raise AnsibleConnectionFailure('Could not find container "{1}" ({0})'.format(e, self.get_option('remote_addr')))
except APIError as e:
if e.response and e.response.status_code == 409:
if e.response is not None and e.response.status_code == 409:
raise AnsibleConnectionFailure('The container "{1}" has been paused ({0})'.format(e, self.get_option('remote_addr')))
self.client.fail(
'An unexpected docker error occurred for container "{1}": {0}'.format(e, self.get_option('remote_addr'))
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/docker_container_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def main():
except NotFound:
client.fail('Could not find container "{0}"'.format(container))
except APIError as e:
if e.response and e.response.status_code == 409:
if e.response is not None and e.response.status_code == 409:
client.fail('The container "{0}" has been paused ({1})'.format(container, to_native(e)))
client.fail('An unexpected docker error occurred: {0}'.format(to_native(e)), exception=traceback.format_exc())
except DockerException as e:
Expand Down

0 comments on commit d33d03b

Please sign in to comment.