godot-gdscript-toolkit
godot-gdscript-toolkit copied to clipboard
UnicodeDecodeError on windows
Just installed the toolkit with pip3 install 'gdtoolkit==3.*'
Launched gdformat --diff .
in the project folder.
I get this output in my terminal:
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Users\admin\AppData\Roaming\Python\Python310\Scripts\gdformat.exe\__main__.py", line 7, in <module>
File "C:\Users\admin\AppData\Roaming\Python\Python310\site-packages\gdtoolkit\formatter\__main__.py", line 69, in main
_check_files_formatting(files, line_length, arguments["--diff"], safety_checks)
File "C:\Users\admin\AppData\Roaming\Python\Python310\site-packages\gdtoolkit\formatter\__main__.py", line 90, in _check_files_formatting
code = fh.read()
File "C:\Program Files\Python310\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 558: character maps to <undefined>
Searching online lead me to https://stackoverflow.com/a/49562606
My guess would be that explicitly setting the encoding to use when opening the file in https://github.com/Scony/godot-gdscript-toolkit/blob/ca2abeeb8723e9951ac028dff4ef12563fd7ae1d/gdtoolkit/formatter/main.py#L89 would fix this, but I'm not sure about all the possible implications this may have. I think Godot by default saves encode files as UTF8, but I'm not sure.
@MatteoPiovanelli-Laser would you be able to share the file/part of the file which fails?
Here's a link to it (from the repo I forked it from) https://github.com/Orama-Interactive/Pixelorama/blob/master/src/Preferences/HandleLanguages.gd
Starting from 72f9faf4820a2c905aabb33b8c45ccabf115e359 all files are loaded with utf-8 encoding. The file will load without problems on the master
branch. So basically this commit needs to be backported or cherrypicked or watever advanced git magic exists for this.
Fixed by 4292c4a, to be released in 3.5
I have not looked into it but #149 and #167 seem to be encoding related as well. Maybe they are obsolete as well.
and where is 3.5 release? only 3.4.0 and 4.0.0 are available 🤔
@Prikalel released today - I was planning to add more features, but I de-scoped that release.
Just checked and both #167 and #149 are indeed fixed when running through the command line. As of the change in code_formatter.py in 5f0da8f it also works in VSCode (would be nice to have a version bump for this)