pre-commit / pre-commit-hooks

Some out-of-the-box hooks for pre-commit
MIT License
5.2k stars 694 forks source link

[end-of-file-fixer] UnicodeEncodeError #1068

Closed v-amorim closed 2 months ago

v-amorim commented 2 months ago

Got this error when it tried to run on a file that has unicode as it's filename (⚙️.code-workspace). It says Failed, but runs "normally" and add the end of file line break.

fix end of files.........................................................Failed
- hook id: end-of-file-fixer
- exit code: 1
- files were modified by this hook

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\User\.cache\pre-commit\repow691ln9o\py_env-python3.12\Scripts\end-of-file-fixer.EXE\__main__.py", line 7, in <module>
  File "C:\Users\User\.cache\pre-commit\repow691ln9o\py_env-python3.12\Lib\site-packages\pre_commit_hooks\end_of_file_fixer.py", line 64, in main
    print(f'Fixing {filename}')
  File "C:\Users\User\.pyenv\pyenv-win\versions\3.12.2\Lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode characters in position 15-16: character maps to <undefined>
asottile commented 2 months ago

your python is not properly configured for utf8 mode