Skip to content

Commit

Permalink
moving the warning wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Vibhu-gslab committed Jun 20, 2024
1 parent 08ca9ab commit f1c5c91
Showing 1 changed file with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ def wrap_plugin_decorator(func: Callable) -> Callable:
@wraps(func)
def plugin_wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
with warnings.catch_warnings(record=True) as w:
# Cause all warnings to always be triggered.
warnings.simplefilter("always")
result = func(*args, **kwargs)
if w:
for warning in w:
Display().warning(str(warning.message))
return result
except UndefinedError as e:
raise AnsibleUndefinedVariable(f"{plugin_type.capitalize()} '{name}' failed: {to_native(e)}", orig_exc=e) from e
except Exception as e:
Expand All @@ -55,19 +62,3 @@ def plugin_wrapper(*args, **kwargs):

wrap_filter = partial(wrap_plugin, "filter")
wrap_test = partial(wrap_plugin, "test")


def warning_wrapper(func):
def wrapper(*args, **kwargs):
with warnings.catch_warnings(record=True) as w:
# Cause all warnings to always be triggered.
warnings.simplefilter("always")
result = func(*args, **kwargs)

# Check if any warnings were issued.
if w:
for warning in w:
Display().warning(str(warning.message)) # Print the warning message
return result

return wrapper

0 comments on commit f1c5c91

Please sign in to comment.