We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Running pre-commit with Python installed from Windows Store raises UnicodeDecodeError
I think it's a special use case and maybe related to the [known issues of this kind of installation](https://docs.python.org/3.7/using/windows.html#known-issues), but still interesting to track it in issues isn't?

And the kind of error surprised me: `UnicodeDecodeError`.

**Reproduce**

1. Install Python through Windows Store
2. Create a virtualenv
3. Install pre-commit and run the hooks

**Environment**

- Windows 10 64 bits
- Python 3.7.6 installed from Windows Store (see: https://docs.python.org/3.7/using/windows.html#windows-store)

**Trace**

```python
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to C:\Users\username/.cache\pre-commit\patch1583836330.
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Initializing environment for https://github.com/python/black.
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Restored changes from C:\Users\username/.cache\pre-commit\patch1583836330.
Traceback (most recent call last):
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\error_handler.py", line 54, in error_handler
    yield
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\main.py", line 371, in main
    return run(args.config, store, args)
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\commands\run.py", line 337, in run
    install_hook_envs(hooks, store)
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\repository.py", line 200, in install_hook_envs
    _hook_install(hook)
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\repository.py", line 83, in _hook_install
    hook.prefix, hook.language_version, hook.additional_dependencies,
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\languages\python.py", line 192, in install_environment
    _make_venv(env_dir, python)
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\languages\python.py", line 204, in make_venv
    cmd_output_b(*cmd, env=env, cwd='/')
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\util.py", line 140, in cmd_output_b
    raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: <exception str() failed>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\username\doculents\git\test-project\.venv\Scripts\pre-commit.exe\__main__.py", line 7, in <module>
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\main.py", line 384, in main
    f'Command {args.command} failed to exit with a returncode',
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\lib\contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\error_handler.py", line 62, in error_handler
    _log_and_exit(msg, e, traceback.format_exc())
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\error_handler.py", line 18, in _log_and_exit
    error_msg = f'{msg}: {type(exc).__name__}: {exc}'
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\util.py", line 115, in __str__
    return self.__bytes__().decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 341: invalid continuation byte
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pre_commit/error_handler.py`
Content:
```
1 import contextlib
2 import functools
3 import os.path
4 import sys
5 import traceback
6 from typing import Generator
7 
8 import pre_commit.constants as C
9 from pre_commit import output
10 from pre_commit.store import Store
11 
12 
13 class FatalError(RuntimeError):
14     pass
15 
16 
17 def _log_and_exit(msg: str, exc: BaseException, formatted: str) -> None:
18     error_msg = f'{msg}: {type(exc).__name__}: {exc}'
19     output.write_line(error_msg)
20     log_path = os.path.join(Store().directory, 'pre-commit.log')
21     output.write_line(f'Check the log at {log_path}')
22 
23     with open(log_path, 'wb') as log:
24         _log_line = functools.partial(output.write_line, stream=log)
25 
26         _log_line('### version information')
27         _log_line()
28         _log_line('```')
29         _log_line(f'pre-commit version: {C.VERSION}')
30         _log_line('sys.version:')
31         for line in sys.version.splitlines():
32             _log_line(f'    {line}')
33         _log_line(f'sys.executable: {sys.executable}')
34         _log_line(f'os.name: {os.name}')
35         _log_line(f'sys.platform: {sys.platform}')
36         _log_line('```')
37         _log_line()
38 
39         _log_line('### error information')
40         _log_line()
41         _log_line('```')
42         _log_line(error_msg)
43         _log_line('```')
44         _log_line()
45         _log_line('```')
46         _log_line(formatted)
47         _log_line('```')
48     raise SystemExit(1)
49 
50 
51 @contextlib.contextmanager
52 def error_handler() -> Generator[None, None, None]:
53     try:
54         yield
55     except (Exception, KeyboardInterrupt) as e:
56         if isinstance(e, FatalError):
57             msg = 'An error has occurred'
58         elif isinstance(e, KeyboardInterrupt):
59             msg = 'Interrupted (^C)'
60         else:
61             msg = 'An unexpected error has occurred'
62         _log_and_exit(msg, e, traceback.format_exc())
63
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pre_commit/error_handler.py b/pre_commit/error_handler.py
--- a/pre_commit/error_handler.py
+++ b/pre_commit/error_handler.py
@@ -14,14 +14,24 @@
     pass
 
 
+def _exception_to_bytes(exc: BaseException) -> bytes:
+    with contextlib.suppress(TypeError):
+        return bytes(exc)  # type: ignore
+    with contextlib.suppress(Exception):
+        return str(exc).encode()
+    return f'<unprintable {type(exc).__name__} object>'.encode()
+
+
 def _log_and_exit(msg: str, exc: BaseException, formatted: str) -> None:
-    error_msg = f'{msg}: {type(exc).__name__}: {exc}'
-    output.write_line(error_msg)
+    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()
@@ -39,7 +49,7 @@
         _log_line('### error information')
         _log_line()
         _log_line('```')
-        _log_line(error_msg)
+        _log_line_b(error_msg)
         _log_line('```')
         _log_line()
         _log_line('```')

{"golden_diff": "diff --git a/pre_commit/error_handler.py b/pre_commit/error_handler.py\n--- a/pre_commit/error_handler.py\n+++ b/pre_commit/error_handler.py\n@@ -14,14 +14,24 @@\n     pass\n \n \n+def _exception_to_bytes(exc: BaseException) -> bytes:\n+    with contextlib.suppress(TypeError):\n+        return bytes(exc)  # type: ignore\n+    with contextlib.suppress(Exception):\n+        return str(exc).encode()\n+    return f'<unprintable {type(exc).__name__} object>'.encode()\n+\n+\n def _log_and_exit(msg: str, exc: BaseException, formatted: str) -> None:\n-    error_msg = f'{msg}: {type(exc).__name__}: {exc}'\n-    output.write_line(error_msg)\n+    error_msg = f'{msg}: {type(exc).__name__}: '.encode()\n+    error_msg += _exception_to_bytes(exc)\n+    output.write_line_b(error_msg)\n     log_path = os.path.join(Store().directory, 'pre-commit.log')\n     output.write_line(f'Check the log at {log_path}')\n \n     with open(log_path, 'wb') as log:\n         _log_line = functools.partial(output.write_line, stream=log)\n+        _log_line_b = functools.partial(output.write_line_b, stream=log)\n \n         _log_line('### version information')\n         _log_line()\n@@ -39,7 +49,7 @@\n         _log_line('### error information')\n         _log_line()\n         _log_line('```')\n-        _log_line(error_msg)\n+        _log_line_b(error_msg)\n         _log_line('```')\n         _log_line()\n         _log_line('```')\n", "issue": "Running pre-commit with Python installed from Windows Store raises UnicodeDecodeError\nI think it's a special use case and maybe related to the [known issues of this kind of installation](https://docs.python.org/3.7/using/windows.html#known-issues), but still interesting to track it in issues isn't?\r\n\r\nAnd the kind of error surprised me: `UnicodeDecodeError`.\r\n\r\n**Reproduce**\r\n\r\n1. Install Python through Windows Store\r\n2. Create a virtualenv\r\n3. Install pre-commit and run the hooks\r\n\r\n**Environment**\r\n\r\n- Windows 10 64 bits\r\n- Python 3.7.6 installed from Windows Store (see: https://docs.python.org/3.7/using/windows.html#windows-store)\r\n\r\n**Trace**\r\n\r\n```python\r\n[WARNING] Unstaged files detected.\r\n[INFO] Stashing unstaged files to C:\\Users\\username/.cache\\pre-commit\\patch1583836330.\r\n[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.\r\n[INFO] Initializing environment for https://github.com/python/black.\r\n[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.\r\n[INFO] Once installed this environment will be reused.\r\n[INFO] This may take a few minutes...\r\n[INFO] Restored changes from C:\\Users\\username/.cache\\pre-commit\\patch1583836330.\r\nTraceback (most recent call last):\r\n  File \"d:\\username\\doculents\\git\\test-project\\.venv\\lib\\site-packages\\pre_commit\\error_handler.py\", line 54, in error_handler\r\n    yield\r\n  File \"d:\\username\\doculents\\git\\test-project\\.venv\\lib\\site-packages\\pre_commit\\main.py\", line 371, in main\r\n    return run(args.config, store, args)\r\n  File \"d:\\username\\doculents\\git\\test-project\\.venv\\lib\\site-packages\\pre_commit\\commands\\run.py\", line 337, in run\r\n    install_hook_envs(hooks, store)\r\n  File \"d:\\username\\doculents\\git\\test-project\\.venv\\lib\\site-packages\\pre_commit\\repository.py\", line 200, in install_hook_envs\r\n    _hook_install(hook)\r\n  File \"d:\\username\\doculents\\git\\test-project\\.venv\\lib\\site-packages\\pre_commit\\repository.py\", line 83, in _hook_install\r\n    hook.prefix, hook.language_version, hook.additional_dependencies,\r\n  File \"d:\\username\\doculents\\git\\test-project\\.venv\\lib\\site-packages\\pre_commit\\languages\\python.py\", line 192, in install_environment\r\n    _make_venv(env_dir, python)\r\n  File \"d:\\username\\doculents\\git\\test-project\\.venv\\lib\\site-packages\\pre_commit\\languages\\python.py\", line 204, in make_venv\r\n    cmd_output_b(*cmd, env=env, cwd='/')\r\n  File \"d:\\username\\doculents\\git\\test-project\\.venv\\lib\\site-packages\\pre_commit\\util.py\", line 140, in cmd_output_b\r\n    raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)\r\npre_commit.util.CalledProcessError: <exception str() failed>\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\\lib\\runpy.py\", line 193, in _run_module_as_main\r\n    \"__main__\", mod_spec)\r\n  File \"C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\\lib\\runpy.py\", line 85, in _run_code\r\n    exec(code, run_globals)\r\n  File \"D:\\username\\doculents\\git\\test-project\\.venv\\Scripts\\pre-commit.exe\\__main__.py\", line 7, in <module>\r\n  File \"d:\\username\\doculents\\git\\test-project\\.venv\\lib\\site-packages\\pre_commit\\main.py\", line 384, in main\r\n    f'Command {args.command} failed to exit with a returncode',\r\n  File \"C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\\lib\\contextlib.py\", line 130, in __exit__\r\n    self.gen.throw(type, value, traceback)\r\n  File \"d:\\username\\doculents\\git\\test-project\\.venv\\lib\\site-packages\\pre_commit\\error_handler.py\", line 62, in error_handler\r\n    _log_and_exit(msg, e, traceback.format_exc())\r\n  File \"d:\\username\\doculents\\git\\test-project\\.venv\\lib\\site-packages\\pre_commit\\error_handler.py\", line 18, in _log_and_exit\r\n    error_msg = f'{msg}: {type(exc).__name__}: {exc}'\r\n  File \"d:\\username\\doculents\\git\\test-project\\.venv\\lib\\site-packages\\pre_commit\\util.py\", line 115, in __str__\r\n    return self.__bytes__().decode()\r\nUnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 341: invalid continuation byte\r\n```\n", "before_files": [{"content": "import contextlib\nimport functools\nimport os.path\nimport sys\nimport traceback\nfrom typing import Generator\n\nimport pre_commit.constants as C\nfrom pre_commit import output\nfrom pre_commit.store import Store\n\n\nclass FatalError(RuntimeError):\n    pass\n\n\ndef _log_and_exit(msg: str, exc: BaseException, formatted: str) -> None:\n    error_msg = f'{msg}: {type(exc).__name__}: {exc}'\n    output.write_line(error_msg)\n    log_path = os.path.join(Store().directory, 'pre-commit.log')\n    output.write_line(f'Check the log at {log_path}')\n\n    with open(log_path, 'wb') as log:\n        _log_line = functools.partial(output.write_line, stream=log)\n\n        _log_line('### version information')\n        _log_line()\n        _log_line('```')\n        _log_line(f'pre-commit version: {C.VERSION}')\n        _log_line('sys.version:')\n        for line in sys.version.splitlines():\n            _log_line(f'    {line}')\n        _log_line(f'sys.executable: {sys.executable}')\n        _log_line(f'os.name: {os.name}')\n        _log_line(f'sys.platform: {sys.platform}')\n        _log_line('```')\n        _log_line()\n\n        _log_line('### error information')\n        _log_line()\n        _log_line('```')\n        _log_line(error_msg)\n        _log_line('```')\n        _log_line()\n        _log_line('```')\n        _log_line(formatted)\n        _log_line('```')\n    raise SystemExit(1)\n\n\n@contextlib.contextmanager\ndef error_handler() -> Generator[None, None, None]:\n    try:\n        yield\n    except (Exception, KeyboardInterrupt) as e:\n        if isinstance(e, FatalError):\n            msg = 'An error has occurred'\n        elif isinstance(e, KeyboardInterrupt):\n            msg = 'Interrupted (^C)'\n        else:\n            msg = 'An unexpected error has occurred'\n        _log_and_exit(msg, e, traceback.format_exc())\n", "path": "pre_commit/error_handler.py"}], "after_files": [{"content": "import contextlib\nimport functools\nimport os.path\nimport sys\nimport traceback\nfrom typing import Generator\n\nimport pre_commit.constants as C\nfrom pre_commit import output\nfrom pre_commit.store import Store\n\n\nclass FatalError(RuntimeError):\n    pass\n\n\ndef _exception_to_bytes(exc: BaseException) -> bytes:\n    with contextlib.suppress(TypeError):\n        return bytes(exc)  # type: ignore\n    with contextlib.suppress(Exception):\n        return str(exc).encode()\n    return f'<unprintable {type(exc).__name__} object>'.encode()\n\n\ndef _log_and_exit(msg: str, exc: BaseException, formatted: str) -> None:\n    error_msg = f'{msg}: {type(exc).__name__}: '.encode()\n    error_msg += _exception_to_bytes(exc)\n    output.write_line_b(error_msg)\n    log_path = os.path.join(Store().directory, 'pre-commit.log')\n    output.write_line(f'Check the log at {log_path}')\n\n    with open(log_path, 'wb') as log:\n        _log_line = functools.partial(output.write_line, stream=log)\n        _log_line_b = functools.partial(output.write_line_b, stream=log)\n\n        _log_line('### version information')\n        _log_line()\n        _log_line('```')\n        _log_line(f'pre-commit version: {C.VERSION}')\n        _log_line('sys.version:')\n        for line in sys.version.splitlines():\n            _log_line(f'    {line}')\n        _log_line(f'sys.executable: {sys.executable}')\n        _log_line(f'os.name: {os.name}')\n        _log_line(f'sys.platform: {sys.platform}')\n        _log_line('```')\n        _log_line()\n\n        _log_line('### error information')\n        _log_line()\n        _log_line('```')\n        _log_line_b(error_msg)\n        _log_line('```')\n        _log_line()\n        _log_line('```')\n        _log_line(formatted)\n        _log_line('```')\n    raise SystemExit(1)\n\n\n@contextlib.contextmanager\ndef error_handler() -> Generator[None, None, None]:\n    try:\n        yield\n    except (Exception, KeyboardInterrupt) as e:\n        if isinstance(e, FatalError):\n            msg = 'An error has occurred'\n        elif isinstance(e, KeyboardInterrupt):\n            msg = 'Interrupted (^C)'\n        else:\n            msg = 'An unexpected error has occurred'\n        _log_and_exit(msg, e, traceback.format_exc())\n", "path": "pre_commit/error_handler.py"}]}