Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ncaq
Copy link

@ncaq ncaq commented Jan 25, 2022

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.

I use GWSL.
And, I got error.

~~~console
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.
@Pololot64
Copy link
Member

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?

@ncaq
Copy link
Author

ncaq commented Jan 26, 2022

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.

@Pololot64
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants