prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  include version information in error log
  would be useful to include things like:
  
  - pre-commit version
  - sys.version
  - sys.executable
  
  --- 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 from __future__ import absolute_import
  2 from __future__ import print_function
  3 from __future__ import unicode_literals
  4 
  5 import contextlib
  6 import os.path
  7 import traceback
  8 
  9 import six
  10 
  11 from pre_commit import five
  12 from pre_commit import output
  13 from pre_commit.store import Store
  14 
  15 
  16 class FatalError(RuntimeError):
  17     pass
  18 
  19 
  20 def _to_bytes(exc):
  21     try:
  22         return bytes(exc)
  23     except Exception:
  24         return six.text_type(exc).encode('UTF-8')
  25 
  26 
  27 def _log_and_exit(msg, exc, formatted):
  28     error_msg = b''.join((
  29         five.to_bytes(msg), b': ',
  30         five.to_bytes(type(exc).__name__), b': ',
  31         _to_bytes(exc), b'\n',
  32     ))
  33     output.write(error_msg)
  34     store = Store()
  35     log_path = os.path.join(store.directory, 'pre-commit.log')
  36     output.write_line('Check the log at {}'.format(log_path))
  37     with open(log_path, 'wb') as log:
  38         output.write(error_msg, stream=log)
  39         output.write_line(formatted, stream=log)
  40     raise SystemExit(1)
  41 
  42 
  43 @contextlib.contextmanager
  44 def error_handler():
  45     try:
  46         yield
  47     except (Exception, KeyboardInterrupt) as e:
  48         if isinstance(e, FatalError):
  49             msg = 'An error has occurred'
  50         elif isinstance(e, KeyboardInterrupt):
  51             msg = 'Interrupted (^C)'
  52         else:
  53             msg = 'An unexpected error has occurred'
  54         _log_and_exit(msg, e, traceback.format_exc())
  55
  ```
  --- 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()
  
  ```
  
golden_diff: 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
  @@ -4,10 +4,12 @@
   
   import contextlib
   import os.path
  +import sys
   import traceback
   
   import six
   
  +import pre_commit.constants as C
   from pre_commit import five
   from pre_commit import output
   from pre_commit.store import Store
  @@ -34,9 +36,36 @@
       store = Store()
       log_path = os.path.join(store.directory, 'pre-commit.log')
       output.write_line('Check the log at {}'.format(log_path))
  +
       with open(log_path, 'wb') as log:
  +        output.write_line(
  +            '### version information\n```', stream=log,
  +        )
  +        output.write_line(
  +            'pre-commit.version: {}'.format(C.VERSION), stream=log,
  +        )
  +        output.write_line(
  +            'sys.version:\n{}'.format(
  +                '\n'.join(
  +                    [
  +                        '    {}'.format(line)
  +                        for line in sys.version.splitlines()
  +                    ],
  +                ),
  +            ),
  +            stream=log,
  +        )
  +        output.write_line(
  +            'sys.executable: {}'.format(sys.executable), stream=log,
  +        )
  +        output.write_line('os.name: {}'.format(os.name), stream=log)
  +        output.write_line(
  +            'sys.platform: {}\n```'.format(sys.platform), stream=log,
  +        )
  +        output.write_line('### error information\n```', stream=log)
           output.write(error_msg, stream=log)
           output.write_line(formatted, stream=log)
  +        output.write('\n```\n', stream=log)
       raise SystemExit(1)
  
verification_info: {"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@@ -4,10 +4,12 @@\n \n import contextlib\n import os.path\n+import sys\n import traceback\n \n import six\n \n+import pre_commit.constants as C\n from pre_commit import five\n from pre_commit import output\n from pre_commit.store import Store\n@@ -34,9 +36,36 @@\n     store = Store()\n     log_path = os.path.join(store.directory, 'pre-commit.log')\n     output.write_line('Check the log at {}'.format(log_path))\n+\n     with open(log_path, 'wb') as log:\n+        output.write_line(\n+            '### version information\\n```', stream=log,\n+        )\n+        output.write_line(\n+            'pre-commit.version: {}'.format(C.VERSION), stream=log,\n+        )\n+        output.write_line(\n+            'sys.version:\\n{}'.format(\n+                '\\n'.join(\n+                    [\n+                        '    {}'.format(line)\n+                        for line in sys.version.splitlines()\n+                    ],\n+                ),\n+            ),\n+            stream=log,\n+        )\n+        output.write_line(\n+            'sys.executable: {}'.format(sys.executable), stream=log,\n+        )\n+        output.write_line('os.name: {}'.format(os.name), stream=log)\n+        output.write_line(\n+            'sys.platform: {}\\n```'.format(sys.platform), stream=log,\n+        )\n+        output.write_line('### error information\\n```', stream=log)\n         output.write(error_msg, stream=log)\n         output.write_line(formatted, stream=log)\n+        output.write('\\n```\\n', stream=log)\n     raise SystemExit(1)\n", "issue": "include version information in error log\nwould be useful to include things like:\r\n\r\n- pre-commit version\r\n- sys.version\r\n- sys.executable\n", "before_files": [{"content": "from __future__ import absolute_import\nfrom __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport contextlib\nimport os.path\nimport traceback\n\nimport six\n\nfrom pre_commit import five\nfrom pre_commit import output\nfrom pre_commit.store import Store\n\n\nclass FatalError(RuntimeError):\n    pass\n\n\ndef _to_bytes(exc):\n    try:\n        return bytes(exc)\n    except Exception:\n        return six.text_type(exc).encode('UTF-8')\n\n\ndef _log_and_exit(msg, exc, formatted):\n    error_msg = b''.join((\n        five.to_bytes(msg), b': ',\n        five.to_bytes(type(exc).__name__), b': ',\n        _to_bytes(exc), b'\\n',\n    ))\n    output.write(error_msg)\n    store = Store()\n    log_path = os.path.join(store.directory, 'pre-commit.log')\n    output.write_line('Check the log at {}'.format(log_path))\n    with open(log_path, 'wb') as log:\n        output.write(error_msg, stream=log)\n        output.write_line(formatted, stream=log)\n    raise SystemExit(1)\n\n\n@contextlib.contextmanager\ndef error_handler():\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": "from __future__ import absolute_import\nfrom __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport contextlib\nimport os.path\nimport sys\nimport traceback\n\nimport six\n\nimport pre_commit.constants as C\nfrom pre_commit import five\nfrom pre_commit import output\nfrom pre_commit.store import Store\n\n\nclass FatalError(RuntimeError):\n    pass\n\n\ndef _to_bytes(exc):\n    try:\n        return bytes(exc)\n    except Exception:\n        return six.text_type(exc).encode('UTF-8')\n\n\ndef _log_and_exit(msg, exc, formatted):\n    error_msg = b''.join((\n        five.to_bytes(msg), b': ',\n        five.to_bytes(type(exc).__name__), b': ',\n        _to_bytes(exc), b'\\n',\n    ))\n    output.write(error_msg)\n    store = Store()\n    log_path = os.path.join(store.directory, 'pre-commit.log')\n    output.write_line('Check the log at {}'.format(log_path))\n\n    with open(log_path, 'wb') as log:\n        output.write_line(\n            '### version information\\n```', stream=log,\n        )\n        output.write_line(\n            'pre-commit.version: {}'.format(C.VERSION), stream=log,\n        )\n        output.write_line(\n            'sys.version:\\n{}'.format(\n                '\\n'.join(\n                    [\n                        '    {}'.format(line)\n                        for line in sys.version.splitlines()\n                    ],\n                ),\n            ),\n            stream=log,\n        )\n        output.write_line(\n            'sys.executable: {}'.format(sys.executable), stream=log,\n        )\n        output.write_line('os.name: {}'.format(os.name), stream=log)\n        output.write_line(\n            'sys.platform: {}\\n```'.format(sys.platform), stream=log,\n        )\n        output.write_line('### error information\\n```', stream=log)\n        output.write(error_msg, stream=log)\n        output.write_line(formatted, stream=log)\n        output.write('\\n```\\n', stream=log)\n    raise SystemExit(1)\n\n\n@contextlib.contextmanager\ndef error_handler():\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"}]}