# Buggy code
def set_owner_if_different(self, path, owner, 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 owner is None:
        return changed
    orig_uid, orig_gid = self.user_and_group(path, expand)
    try:
        uid = int(owner)
    except ValueError:
        try:
            uid = pwd.getpwnam(owner).pw_uid
        except KeyError:
            self.fail_json(
                path=path, msg="chown failed: failed to look up user %s" % owner
            )
    if orig_uid != uid:
        if diff is not None:
            if "before" not in diff:
                diff["before"] = {}
            diff["before"]["owner"] = orig_uid
            if "after" not in diff:
                diff["after"] = {}
            diff["after"]["owner"] = uid

        if self.check_mode:
            return True
        try:
            os.lchown(b_path, uid, -1)
        except OSError:
            self.fail_json(path=path, msg="chown 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_owner_if_different(self, path, owner, 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))
    if owner is None:
        return changed
    orig_uid, orig_gid = self.user_and_group(b_path, expand)
    try:
        uid = int(owner)
    except ValueError:
        try:
            uid = pwd.getpwnam(owner).pw_uid
        except KeyError:
            path = to_text(b_path)
            self.fail_json(
                path=path, msg="chown failed: failed to look up user %s" % owner
            )

    if orig_uid != uid:
        if diff is not None:
            if "before" not in diff:
                diff["before"] = {}
            diff["before"]["owner"] = orig_uid
            if "after" not in diff:
                diff["after"] = {}
            diff["after"]["owner"] = uid

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