# Buggy code
def _log_and_exit(msg: str, exc: BaseException, formatted: str) -> None:
    error_msg = f"{msg}: {type(exc).__name__}: ".encode()
    error_msg += _exception_to_bytes(exc)
    output.write_line_b(error_msg)
    log_path = os.path.join(Store().directory, "pre-commit.log")
    output.write_line(f"Check the log at {log_path}")

    with open(log_path, "wb") as log:
        _log_line = functools.partial(output.write_line, stream=log)
        _log_line_b = functools.partial(output.write_line_b, stream=log)

        _log_line("### version information")
        _log_line()
        _log_line("```")
        _log_line(f"pre-commit version: {C.VERSION}")
        _log_line("sys.version:")
        for line in sys.version.splitlines():
            _log_line(f"    {line}")
        _log_line(f"sys.executable: {sys.executable}")
        _log_line(f"os.name: {os.name}")
        _log_line(f"sys.platform: {sys.platform}")
        _log_line("```")
        _log_line()

        _log_line("### error information")
        _log_line()
        _log_line("```")
        _log_line_b(error_msg)
        _log_line("```")
        _log_line()
        _log_line("```")
        _log_line(formatted)
        _log_line("```")
    raise SystemExit(1)


# Traceback (OSError)
Traceback (most recent call last):
File "/[redacted]/venv/lib/python3.7/site-packages/pre_commit/error_handler.py", line 54, in error_handler
yield
File "/[redacted]/venv/lib/python3.7/site-packages/pre_commit/main.py", line 371, in main
return run(args.config, store, args)
File "/[redacted]/venv/lib/python3.7/site-packages/pre_commit/commands/run.py", line 339, in run
return _run_hooks(config, hooks, args, environ)
File "/[redacted]/venv/lib/python3.7/site-packages/pre_commit/commands/run.py", line 249, in _run_hooks
verbose=args.verbose, use_color=args.color,
File "/[redacted]/venv/lib/python3.7/site-packages/pre_commit/commands/run.py", line 165, in _run_single_hook
retcode, out = language.run_hook(hook, filenames, use_color)
File "/[redacted]/venv/lib/python3.7/site-packages/pre_commit/languages/script.py", line 19, in run_hook
return helpers.run_xargs(hook, cmd, file_args, color=color)
File "/[redacted]/venv/lib/python3.7/site-packages/pre_commit/languages/helpers.py", line 109, in run_xargs
return xargs(cmd, file_args, **kwargs)
File "/[redacted]/venv/lib/python3.7/site-packages/pre_commit/xargs.py", line 153, in xargs
for proc_retcode, proc_out, _ in results:
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py", line 598, in result_iterator
yield fs.pop().result()
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py", line 428, in result
return self.__get_result()
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
raise self._exception
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/[redacted]/venv/lib/python3.7/site-packages/pre_commit/xargs.py", line 146, in run_cmd_partition
*run_cmd, retcode=None, stderr=subprocess.STDOUT, **kwargs,
File "/[redacted]/venv/lib/python3.7/site-packages/pre_commit/util.py", line 208, in cmd_output_p
proc = subprocess.Popen(cmd, **kwargs)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 800, in __init__
restore_signals, start_new_session)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: '/[redacted]/foo.py'

# Fixed code
def _log_and_exit(msg: str, exc: BaseException, formatted: str) -> None:
    error_msg = f"{msg}: {type(exc).__name__}: ".encode() + force_bytes(exc)
    output.write_line_b(error_msg)
    log_path = os.path.join(Store().directory, "pre-commit.log")
    output.write_line(f"Check the log at {log_path}")

    with open(log_path, "wb") as log:
        _log_line = functools.partial(output.write_line, stream=log)
        _log_line_b = functools.partial(output.write_line_b, stream=log)

        _log_line("### version information")
        _log_line()
        _log_line("```")
        _log_line(f"pre-commit version: {C.VERSION}")
        _log_line("sys.version:")
        for line in sys.version.splitlines():
            _log_line(f"    {line}")
        _log_line(f"sys.executable: {sys.executable}")
        _log_line(f"os.name: {os.name}")
        _log_line(f"sys.platform: {sys.platform}")
        _log_line("```")
        _log_line()

        _log_line("### error information")
        _log_line()
        _log_line("```")
        _log_line_b(error_msg)
        _log_line("```")
        _log_line()
        _log_line("```")
        _log_line(formatted)
        _log_line("```")
    raise SystemExit(1)