# Buggy code
def set_group_if_different(self, path, group, changed, diff=None, expand=True):
    b_path = to_bytes(path, errors="surrogate_then_strict")
    if expand:
        b_path = os.path.expanduser(os.path.expandvars(b_path))
    path = to_text(b_path, errors="surrogate_then_strict")
    if group is None:
        return changed
    orig_uid, orig_gid = self.user_and_group(b_path, expand)
    try:
        gid = int(group)
    except ValueError:
        try:
            gid = grp.getgrnam(group).gr_gid
        except KeyError:
            self.fail_json(
                path=path, msg="chgrp failed: failed to look up group %s" % group
            )
    if orig_gid != gid:
        if diff is not None:
            if "before" not in diff:
                diff["before"] = {}
            diff["before"]["group"] = orig_gid
            if "after" not in diff:
                diff["after"] = {}
            diff["after"]["group"] = gid

        if self.check_mode:
            return True
        try:
            os.lchown(b_path, -1, gid)
        except OSError:
            self.fail_json(path=path, msg="chgrp failed")
        changed = True
    return changed


# Traceback (LookupError)
exception:
Traceback (most recent call last):
File "/tmp/ansible_atAUEE/ansible_module_file.py", line 480, in <module>
main()
File "/tmp/ansible_atAUEE/ansible_module_file.py", line 362, in main
changed |= recursive_set_attributes(module, to_bytes(file_args['path'], errors='surrogate_or_strict'), follow, file_args)
File "/tmp/ansible_atAUEE/ansible_module_file.py", line 171, in recursive_set_attributes
changed |= module.set_fs_attributes_if_different(tmp_file_args, changed)
File "/tmp/ansible_atAUEE/ansible_modlib.zip/ansible/module_utils/basic.py", line 1292, in set_fs_attributes_if_different
File "/tmp/ansible_atAUEE/ansible_modlib.zip/ansible/module_utils/basic.py", line 995, in set_owner_if_different
File "/tmp/ansible_atAUEE/ansible_modlib.zip/ansible/module_utils/_text.py", line 232, in to_text
File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
LookupError: unknown error handler name 'surrogate_then_strict'

# Fixed code
def set_group_if_different(self, path, group, changed, diff=None, expand=True):
    b_path = to_bytes(path, errors="surrogate_or_strict")
    if expand:
        b_path = os.path.expanduser(os.path.expandvars(b_path))
    path = to_text(b_path, errors="surrogate_or_strict")
    if group is None:
        return changed
    orig_uid, orig_gid = self.user_and_group(b_path, expand)
    try:
        gid = int(group)
    except ValueError:
        try:
            gid = grp.getgrnam(group).gr_gid
        except KeyError:
            self.fail_json(
                path=path, msg="chgrp failed: failed to look up group %s" % group
            )
    if orig_gid != gid:
        if diff is not None:
            if "before" not in diff:
                diff["before"] = {}
            diff["before"]["group"] = orig_gid
            if "after" not in diff:
                diff["after"] = {}
            diff["after"]["group"] = gid

        if self.check_mode:
            return True
        try:
            os.lchown(b_path, -1, gid)
        except OSError:
            self.fail_json(path=path, msg="chgrp failed")
        changed = True
    return changed