From 44e2cbe7b7bf41703ef2eb45faa1f59962eb3b34 Mon Sep 17 00:00:00 2001 From: Dhanuka <42544330+dnuka@users.noreply.github.com> Date: Thu, 20 Dec 2018 17:43:24 +0530 Subject: [PATCH] Update `Unknown error` to specific error message (#50129) * Update `Unknown error` to specific error message outputs the Exception received rather than just 'Unknown error' fixes: issue/49713 * Update `Unknown error` to specific error message improves the error message --- lib/ansible/module_utils/redfish_utils.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index a1fb9325c8..a3a3d38932 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -7,6 +7,7 @@ __metaclass__ = type import json import re from ansible.module_utils.urls import open_url +from ansible.module_utils._text import to_text from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError HEADERS = {'content-type': 'application/json'} @@ -35,8 +36,9 @@ class RedfishUtils(object): except URLError as e: return {'ret': False, 'msg': "URL Error: %s" % e.reason} # Almost all errors should be caught above, but just in case - except Exception: - return {'ret': False, 'msg': "Unknown error"} + except Exception as e: + return {'ret': False, + 'msg': 'Failed GET operation against Redfish API server: %s' % to_text(e)} return {'ret': True, 'data': data} def post_request(self, uri, pyld, hdrs): @@ -53,8 +55,9 @@ class RedfishUtils(object): except URLError as e: return {'ret': False, 'msg': "URL Error: %s" % e.reason} # Almost all errors should be caught above, but just in case - except Exception: - return {'ret': False, 'msg': "Unknown error"} + except Exception as e: + return {'ret': False, + 'msg': 'Failed POST operation against Redfish API server: %s' % to_text(e)} return {'ret': True, 'resp': resp} def patch_request(self, uri, pyld, hdrs): @@ -71,8 +74,9 @@ class RedfishUtils(object): except URLError as e: return {'ret': False, 'msg': "URL Error: %s" % e.reason} # Almost all errors should be caught above, but just in case - except Exception: - return {'ret': False, 'msg': "Unknown error"} + except Exception as e: + return {'ret': False, + 'msg': 'Failed PATCH operation against Redfish API server: %s' % to_text(e)} return {'ret': True, 'resp': resp} def delete_request(self, uri, pyld, hdrs): @@ -89,8 +93,9 @@ class RedfishUtils(object): except URLError as e: return {'ret': False, 'msg': "URL Error: %s" % e.reason} # Almost all errors should be caught above, but just in case - except Exception: - return {'ret': False, 'msg': "Unknown error"} + except Exception as e: + return {'ret': False, + 'msg': 'Failed DELETE operation against Redfish API server: %s' % to_text(e)} return {'ret': True, 'resp': resp} def _init_session(self):