git-ai-commit icon indicating copy to clipboard operation
git-ai-commit copied to clipboard

support utf-8 encoding in `hook_handler.py`

Open kingstondoesit opened this issue 11 months ago • 0 comments

when I run the command git-ai-commit config --setup after package installation, I immediately encounter this error:

Welcome to AI Commit MSG! Let's get you set up.

[Setup] Git prepare-commit-msg 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_NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\Scripts\git-ai-commit.exe\__main__.py", line 7, in <module>
  File "C:\Users\USER_NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\ai_commit_msg\main.py", line 154, in main
    config_handler(args)
  File "C:\Users\USER_NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\ai_commit_msg\cli\config_handler.py", line 50, in config_handler
    handle_config_setup()
  File "C:\Users\USER_NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\ai_commit_msg\cli\config_handler.py", line 9, in handle_config_setup
    onboarding_flow()
  File "C:\Users\USER_NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\ai_commit_msg\services\onboarding_service.py", line 81, in onboarding_flow
    setup_git_hook()
  File "C:\Users\USER_NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\ai_commit_msg\cli\hook_handler.py", line 99, in setup_git_hook
    handle_setup_hook(file_path)
  File "C:\Users\USER_NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\ai_commit_msg\cli\hook_handler.py", line 56, in handle_setup_hook
    file.write(get_bash_script())
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.2288.0_x64__qbz5n2kfra8p0\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 273-274: character maps to <undefined>

Only after I modified the handle_setup_hook() function in hook_handler.py to handle utf-8 encodes did it get to work.

kingstondoesit avatar Dec 23 '24 07:12 kingstondoesit