godot-gdscript-toolkit icon indicating copy to clipboard operation
godot-gdscript-toolkit copied to clipboard

UnicodeDecodeError on windows

Open MatteoPiovanelli-Laser opened this issue 2 years ago • 2 comments

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 avatar Apr 02 '22 16:04 MatteoPiovanelli-Laser

@MatteoPiovanelli-Laser would you be able to share the file/part of the file which fails?

Scony avatar Apr 02 '22 16:04 Scony

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

MatteoPiovanelli-Laser avatar Apr 02 '22 18:04 MatteoPiovanelli-Laser

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.

HolonProduction avatar Feb 07 '23 21:02 HolonProduction

Fixed by 4292c4a, to be released in 3.5

Scony avatar Feb 08 '23 19:02 Scony

I have not looked into it but #149 and #167 seem to be encoding related as well. Maybe they are obsolete as well.

HolonProduction avatar Feb 08 '23 19:02 HolonProduction

and where is 3.5 release? only 3.4.0 and 4.0.0 are available 🤔

Prikalel avatar Mar 12 '23 11:03 Prikalel

@Prikalel released today - I was planning to add more features, but I de-scoped that release.

Scony avatar Mar 15 '23 20:03 Scony

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)

Cammymoop avatar Jun 25 '23 03:06 Cammymoop