# Buggy code
def decode_output(output):
    if not isinstance(output, six.string_types):
        return output
    try:
        output = output.encode(DEFAULT_ENCODING)
    except (AttributeError, UnicodeDecodeError):
        if six.PY2:
            output = unicode.translate(
                vistir.misc.to_text(output), UNICODE_TO_ASCII_TRANSLATION_MAP
            )
        else:
            output = output.translate(UNICODE_TO_ASCII_TRANSLATION_MAP)
    output = output.decode(DEFAULT_ENCODING)
    return output


# Traceback (UnicodeEncodeError)
$ python3 -m venv env
$ env/bin/python -m pip install pipenv
$ LANG=fr_FR env/bin/pipenv install
Traceback (most recent call last):
File "env/bin/pipenv", line 11, in <module>
sys.exit(cli())
File "/home/vstinner/env/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/home/vstinner/env/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/home/vstinner/env/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/vstinner/env/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/vstinner/env/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/home/vstinner/env/lib/python3.6/site-packages/pipenv/vendor/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/home/vstinner/env/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/home/vstinner/env/lib/python3.6/site-packages/pipenv/vendor/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/vstinner/env/lib64/python3.6/site-packages/pipenv/cli/command.py", line 249, in install
editable_packages=state.installstate.editables,
File "/home/vstinner/env/lib64/python3.6/site-packages/pipenv/core.py", line 1975, in do_install
skip_lock=skip_lock,
File "/home/vstinner/env/lib64/python3.6/site-packages/pipenv/core.py", line 1282, in do_init
pypi_mirror=pypi_mirror,
File "/home/vstinner/env/lib64/python3.6/site-packages/pipenv/core.py", line 708, in do_install_dependencies
bold=True,
File "/home/vstinner/env/lib/python3.6/site-packages/pipenv/vendor/click/utils.py", line 260, in echo
file.write(message)
UnicodeEncodeError: 'latin-1' codec can't encode character '\u2026' in position 59: ordinal not in range(256)

# Fixed code
def decode_output(output):
    if not isinstance(output, six.string_types):
        return output
    try:
        output = output.encode(DEFAULT_ENCODING)
    except (AttributeError, UnicodeDecodeError, UnicodeEncodeError):
        if six.PY2:
            output = unicode.translate(
                vistir.misc.to_text(output), UNICODE_TO_ASCII_TRANSLATION_MAP
            )
        else:
            output = output.translate(UNICODE_TO_ASCII_TRANSLATION_MAP)
        output = output.encode(DEFAULT_ENCODING, "replace")
    return vistir.misc.to_text(output, encoding=DEFAULT_ENCODING, errors="replace")
    return output