Unicode decoding issue on Windows
See original GitHub issueWhen trying to decode Unicode characters on Windows, gitlint can crash. This can easily be shown by trying to lint the commit 3ee281eec4ef4325ce90d27f6f368a6b95818cfe of the gitlint commit history.
(.venv) C:\Users\Administrator\gitlint>gitlint --commits 3ee281eec4ef4325ce90d27f6f368a6b95818cfe
Traceback (most recent call last):
File "C:\Users\Administrator\gitlint\gitlint\.venv\Scripts\gitlint-script.py", line 11, in <module>
load_entry_point('gitlint', 'console_scripts', 'gitlint')()
File "C:\Users\Administrator\gitlint\gitlint\.venv\lib\site-packages\click\core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "C:\Users\Administrator\gitlint\gitlint\.venv\lib\site-packages\click\core.py", line 717, in main
rv = self.invoke(ctx)
File "C:\Users\Administrator\gitlint\gitlint\.venv\lib\site-packages\click\core.py", line 1114, in invoke
return Command.invoke(self, ctx)
File "C:\Users\Administrator\gitlint\gitlint\.venv\lib\site-packages\click\core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Users\Administrator\gitlint\gitlint\.venv\lib\site-packages\click\core.py", line 555, in invoke
return callback(*args, **kwargs)
File "C:\Users\Administrator\gitlint\gitlint\.venv\lib\site-packages\click\decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "c:\users\administrator\gitlint\gitlint\cli.py", line 180, in cli
ctx.invoke(lint)
File "C:\Users\Administrator\gitlint\gitlint\.venv\lib\site-packages\click\core.py", line 555, in invoke
return callback(*args, **kwargs)
File "C:\Users\Administrator\gitlint\gitlint\.venv\lib\site-packages\click\decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "c:\users\administrator\gitlint\gitlint\cli.py", line 211, in lint
gitcontext = GitContext.from_local_repository(lint_config.target, ctx.obj[2])
File "c:\users\administrator\gitlint\gitlint\git.py", line 199, in from_local_repository
raw_commit = _git("log", sha, "-1", long_format, _cwd=repository_path).split("\n")
File "c:\users\administrator\gitlint\gitlint\git.py", line 28, in _git
result = sh.git(*command_parts, **git_kwargs) # pylint: disable=unexpected-keyword-arg
File "c:\users\administrator\gitlint\gitlint\shell.py", line 45, in git
return _exec(*args, **kwargs)
File "c:\users\administrator\gitlint\gitlint\shell.py", line 65, in _exec
stdout = ustr(result[0])
File "c:\users\administrator\gitlint\gitlint\utils.py", line 27, in ustr
return unicode(obj, DEFAULT_ENCODING) # pragma: no cover # noqa
File "C:\Users\Administrator\gitlint\gitlint\.venv\lib\encodings\cp1252.py", line 15, in decode
return codecs.charmap_decode(input,errors,decoding_table)
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 1: character maps to <undefined>
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Errors caused by Windows 10 Unicode UTF-8 encoding – nShift
Errors caused by Windows 10 Unicode UTF-8 encoding · Close nShift On-premises. · Delete the Consignor folder under AppData. · Open Windows Control ......
Read more >How to solve unicode encoding issues - Invivoo
In ths new article, our expert will explain you how to solve unicode encoding issues. If you have any question, don't hesite to...
Read more >Chinese characters SOMETIMES not decoded properly in ...
Chinese characters SOMETIMES not decoded properly in Windows 10 · Press Windows key + X. · Click Control Panel. · Click Clock, Language,...
Read more >Change Character Encoding (Windows Users) · Learn Twarc!
Under 'Language for non-Unicode Programs', click the button for 'Change system locale…' Screenshot of unicode encode error. Check the box for 'Beta: Use...
Read more >How to Fix Language Problem of Non Unicode Program in ...
How to Fix Language Problem of Non Unicode Program in Windows 10.This tutorial will apply for computers, laptops, desktops,and tablets ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Is it here I should write about a bug?
when I install gitlint hook by pre-commit in linux it works normally, but in windows it failed with error
Even if the commit message is perfectly valid.
@metya, can you try setting
LC_ALL
toUTF-8
and let me know if that works for you?The reason this happens is because git sets
LC_CTYPE=C
on Windows when invoking/bin/sh
, and Python can’t find theC
encoding. I’ve added a workaround in #158, adding some logic for gitlint to more smartly fall back toUTF-8
. This will go out as part of the 0.14.0 release within the next month.This doesn’t solve all unicode issues on Windows (I’ve spend more time on it but no silver bullets…yet), but hopefully it should keep gitlint from crashing.