Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
k8s: Handle ValueError raised (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
Akasurde authored Jan 12, 2021
1 parent a6cb6c4 commit 9059f2c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/handle_valueerror.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- k8s - handle ValueError when namespace is not provided (https://github.com/ansible-collections/community.kubernetes/pull/330).
9 changes: 7 additions & 2 deletions plugins/module_utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,8 @@ def perform_action(self, resource, definition):
except DynamicApiError as exc:
self.fail_json(msg='Failed to retrieve requested object: {0}'.format(exc.body),
error=exc.status, status=exc.status, reason=exc.reason)
except Exception as exc:
self.fail_json(msg='Failed to retrieve requested object: {0}'.format(to_native(exc)),
except ValueError as value_exc:
self.fail_json(msg='Failed to retrieve requested object: {0}'.format(to_native(value_exc)),
error='', status='', reason='')

if state == 'absent':
Expand Down Expand Up @@ -708,6 +708,11 @@ def perform_action(self, resource, definition):
if self.warnings:
msg += "\n" + "\n ".join(self.warnings)
self.fail_json(msg=msg, error=exc.status, status=exc.status, reason=exc.reason)
except Exception as exc:
msg = "Failed to create object: {0}".format(exc)
if self.warnings:
msg += "\n" + "\n ".join(self.warnings)
self.fail_json(msg=msg, error='', status='', reason='')
success = True
result['result'] = k8s_obj
if wait and not self.check_mode:
Expand Down

0 comments on commit 9059f2c

Please sign in to comment.