# Buggy code
def decode_list(
    data,
    encoding=None,
    errors="strict",
    preserve_dict_class=False,
    preserve_tuples=False,
):
    """
    Decode all string values to Unicode
    """
    rv = []
    for item in data:
        if isinstance(item, list):
            item = decode_list(
                item, encoding, errors, preserve_dict_class, preserve_tuples
            )
        elif isinstance(item, tuple):
            item = (
                decode_tuple(item, encoding, errors, preserve_dict_class)
                if preserve_tuples
                else decode_list(
                    item, encoding, errors, preserve_dict_class, preserve_tuples
                )
            )
        elif isinstance(item, collections.Mapping):
            item = decode_dict(
                item, encoding, errors, preserve_dict_class, preserve_tuples
            )
        else:
            try:
                item = salt.utils.stringutils.to_unicode(item, encoding, errors)
            except TypeError:
                pass

        rv.append(item)
    return rv


# Traceback (UnicodeEncodeError)
ID: test1
Function: file.recurse
Name: /root/group2test
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/state.py", line 1746, in call
**cdata['kwargs'])
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1703, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python2.6/site-packages/salt/states/file.py", line 2807, in recurse
manage_file(dest, src)
File "/usr/lib/python2.6/site-packages/salt/states/file.py", line 2685, in manage_file
**pass_kwargs)
File "/usr/lib/python2.6/site-packages/salt/states/file.py", line 1814, in managed
__env__
File "/usr/lib/python2.6/site-packages/salt/modules/file.py", line 3490, in source_list
contextkey = '{0}_|-{1}_|-{2}'.format(source, source_hash, saltenv)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 31-34: ordinal not in range(128)
Started: 20:08:21.608398
Duration: 1467.811 ms
Changes:

# Fixed code
def decode_list(
    data,
    encoding=None,
    errors="strict",
    keep=False,
    preserve_dict_class=False,
    preserve_tuples=False,
):
    """
    Decode all string values to Unicode
    """
    rv = []
    for item in data:
        if isinstance(item, list):
            item = decode_list(
                item, encoding, errors, keep, preserve_dict_class, preserve_tuples
            )
        elif isinstance(item, tuple):
            item = (
                decode_tuple(item, encoding, errors, keep, preserve_dict_class)
                if preserve_tuples
                else decode_list(
                    item, encoding, errors, keep, preserve_dict_class, preserve_tuples
                )
            )
        elif isinstance(item, collections.Mapping):
            item = decode_dict(
                item, encoding, errors, keep, preserve_dict_class, preserve_tuples
            )
        else:
            try:
                item = salt.utils.stringutils.to_unicode(item, encoding, errors)
            except TypeError:
                pass
            except UnicodeDecodeError:
                if not keep:
                    raise

        rv.append(item)
    return rv