GWSL-Source icon indicating copy to clipboard operation
GWSL-Source copied to clipboard

fixed: when non ASCII character in .profile on CJK Windows

Open ncaq opened this issue 3 years ago • 3 comments
trafficstars

I use GWSL. And, I got error.

2021-12-07 00:57:32,949 - GWSL 1.4.0 - ERROR - Exception occurred - Error in Mainloop
Traceback (most recent call last):
  File "manager.py", line 4451, in <module>
  File "manager.py", line 4061, in draw
  File "manager.py", line 4014, in apper
  File "manager.py", line 2266, in app_launcher
  File "manager.py", line 2805, in spawn_n_run
  File "wsl_tools.py", line 191, in profile
UnicodeDecodeError: 'cp932' codec can't decode byte 0x86 in position 586: illegal multibyte sequence

I research.

I found the cause of this error to be the following.

In Japanese Windows, the default system character set is cp932 (Shift_JIS). Therefore, Python also basically tries to handle strings as cp932. However, in GNU/Linux, the character encoding of files is basically ASCII or UTF-8. At least, it will be more than cp932. Therefore, when reading `.profile', it is better to expect UTF-8 and read it with a higher success rate. Therefore, I basically rewrote the wsl.exe process to assume that the return value of the process is UTF-8 and decode it.

ncaq avatar Jan 25 '22 09:01 ncaq

Thanks for the PR. I will test it in a bit, but I have a quick question since I can't get to it immediately. When the process runs, does it spawn a black cmd window?

Pololot64 avatar Jan 25 '22 18:01 Pololot64

I hadn't taken that into account. This PR is a result of the fact that I thought it would be better to include a simple fix rather than just writing an issue about how a simple Python open only works strangely on Japanese Windows.

ncaq avatar Jan 26 '22 09:01 ncaq

It's not a problem. Pr's are good. I am thinking there has got to be a way to decode stuff properly with the current system. I'll look into it if you want.

Thanks again, Paul

Pololot64 avatar Jan 26 '22 17:01 Pololot64