Skip to content

Commit

Permalink
Show field instead of value (ansible#59926)
Browse files Browse the repository at this point in the history
* Show argument name vs value on failed conversion

  generally more useful to user as they might set values indirectly

* clog
  • Loading branch information
bcoca authored Feb 21, 2020
1 parent 542d1b9 commit 00b70bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/show_field_instead_of_value.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- An invalid value is hard to track down if you don't know where it came from, return field name instead.
7 changes: 5 additions & 2 deletions lib/ansible/module_utils/common/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _return_datastructure_name(obj):
elif isinstance(obj, tuple(list(integer_types) + [float])):
yield to_native(obj, nonstring='simplerepr')
else:
raise TypeError('Unknown parameter type: %s, %s' % (type(obj), obj))
raise TypeError('Unknown parameter type: %s' % (type(obj)))


def list_no_log_values(argument_spec, params):
Expand All @@ -86,7 +86,10 @@ def list_no_log_values(argument_spec, params):
no_log_object = params.get(arg_name, None)

if no_log_object:
no_log_values.update(_return_datastructure_name(no_log_object))
try:
no_log_values.update(_return_datastructure_name(no_log_object))
except TypeError as e:
raise TypeError('Failed to convert "%s": %s' % (arg_name, to_native(e)))

# Get no_log values from suboptions
sub_argument_spec = arg_opts.get('options')
Expand Down

0 comments on commit 00b70bf

Please sign in to comment.