Skip to content

Commit b0249f3

Browse files
[Enhancement][1765]enhance_error_message_when_faiiling_to_import (#1804)
* Classes for Exception on required by python * Correct creation of zoau * Continue experimenting * Fix issue * Fix lint * Add fragment * Update changelogs/fragments/1804_enhance_error_message_when_failing_import.yml Co-authored-by: Fernando Flores <[email protected]> * Fix docstring --------- Co-authored-by: Fernando Flores <[email protected]>
1 parent aa418bc commit b0249f3

File tree

2 files changed

+31
-38
lines changed

2 files changed

+31
-38
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
minor_changes:
2+
- module_utils/import_handler - When importing a non supported ZOAU version like 1.2.x the module would throw a non user friendly error message.
3+
Error message is now explicit about ZOAU not being properly configured for Ansible.
4+
(https://github.com/ansible-collections/ibm_zos_core/pull/1804).

plugins/module_utils/import_handler.py

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def method(*args, **kwargs):
3939
"Ensure environment variables are properly configured in Ansible for use with ZOAU."
4040
)
4141
)
42-
4342
return method
4443

4544

@@ -81,30 +80,25 @@ def __getattr__(self, name):
8180
and instead return a method that will alert the user that there was
8281
an error while importing ZOAU.
8382
"""
84-
def method(*args, **kwargs):
85-
"""Raises ImportError as a result of a failed ZOAU import.
83+
"""Raises ImportError as a result of a failed ZOAU import.
8684
87-
Parameters
88-
----------
89-
*args : dict
90-
Arguments ordered in a dictionary.
91-
**kwargs : dict
92-
Arguments ordered in a dictionary.
85+
Parameters
86+
----------
87+
name : str
88+
Value of object not properly imported.
9389
94-
Raises
95-
------
96-
ImportError
97-
Unable to import a module or library.
98-
"""
99-
raise ImportError(
100-
(
101-
"ZOAU is not properly configured for Ansible. Unable to import zoautil_py. "
102-
"Ensure environment variables are properly configured in Ansible for use with ZOAU. "
103-
"Complete traceback: {0}".format(self.traceback)
104-
)
90+
Raises
91+
------
92+
ImportError
93+
Unable to import a module or library.
94+
"""
95+
raise ImportError(
96+
(
97+
"ZOAU is not properly configured for Ansible. Unable to import zoautil_py. "
98+
"Ensure environment variables are properly configured in Ansible for use with ZOAU. "
99+
"Complete traceback: {0}".format(self.traceback)
105100
)
106-
107-
return method
101+
)
108102

109103

110104
class MissingImport(object):
@@ -124,21 +118,16 @@ def __init__(self, import_name=""):
124118
self.import_name = import_name
125119

126120
def __getattr__(self, name):
127-
def method(*args, **kwargs):
128-
"""Raises ImportError as a result of trying to import a missing module.
129-
130-
Parameter
131-
---------
132-
*args : dict
133-
Arguments ordered in a dictionary.
134-
**kwargs : dict
135-
Arguments ordered in a dictionary.
121+
"""Raises ImportError as a result of trying to import a missing module.
136122
137-
Raises
138-
------
139-
ImportError
140-
Unable to import a module or library.
141-
"""
142-
raise ImportError("Import {0} was not available.".format(self.import_name))
123+
Parameter
124+
---------
125+
name : str
126+
Value of object not properly imported.
143127
144-
return method
128+
Raises
129+
------
130+
ImportError
131+
Unable to import a module or library.
132+
"""
133+
raise ImportError("Import {0} was not available.".format(self.import_name))

0 commit comments

Comments
 (0)