Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-commit install fails if existing hook is not utf-8 #1942

Closed
sbienkow-ninja opened this issue Jun 15, 2021 · 0 comments · Fixed by #1943
Closed

Pre-commit install fails if existing hook is not utf-8 #1942

sbienkow-ninja opened this issue Jun 15, 2021 · 0 comments · Fixed by #1943
Labels

Comments

@sbienkow-ninja
Copy link

@sbienkow-ninja sbienkow-ninja commented Jun 15, 2021

It looks like pre-commit tries to read the contents of an already installed hook blindly, without first checking if its a text file and not binary blob.

version information

pre-commit version: 2.13.0
sys.version:
    3.8.5 (default, May 27 2021, 13:30:53) 
    [GCC 9.3.0]
sys.executable: /usr/bin/python3
os.name: posix
sys.platform: linux

error information

An unexpected error has occurred: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 40: invalid continuation byte
Traceback (most recent call last):
  File "/home/user/.local/lib/python3.8/site-packages/pre_commit/error_handler.py", line 65, in error_handler
    yield
  File "/home/user/.local/lib/python3.8/site-packages/pre_commit/main.py", line 367, in main
    return install(
  File "/home/user/.local/lib/python3.8/site-packages/pre_commit/commands/install_uninstall.py", line 139, in install
    _install_hook_script(
  File "/home/user/.local/lib/python3.8/site-packages/pre_commit/commands/install_uninstall.py", line 88, in _install_hook_script
    if os.path.lexists(hook_path) and not is_our_script(hook_path):
  File "/home/user/.local/lib/python3.8/site-packages/pre_commit/commands/install_uninstall.py", line 52, in is_our_script
    contents = f.read()
  File "/usr/lib/python3.8/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 40: invalid continuation byte
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants