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

UnicodeDecodeError when using thefuck #994

Closed
KishinZW opened this issue Oct 26, 2019 · 6 comments · Fixed by #1214
Closed

UnicodeDecodeError when using thefuck #994

KishinZW opened this issue Oct 26, 2019 · 6 comments · Fixed by #1214
Assignees
Milestone

Comments

@KishinZW
Copy link

I followed the alias guide, but I got an error when running thefuck in PowerShell:

Traceback (most recent call last):
  File "d:\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "d:\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\Python36\Scripts\thefuck.exe\__main__.py", line 9, in <module>
  File "d:\python36\lib\site-packages\thefuck\entrypoints\main.py", line 26, in main
    fix_command(known_args)
  File "d:\python36\lib\site-packages\thefuck\entrypoints\fix_command.py", line 36, in fix_command
    command = types.Command.from_raw_script(raw_command)
  File "d:\python36\lib\site-packages\thefuck\types.py", line 82, in from_raw_script
    output = get_output(script, expanded)
  File "d:\python36\lib\site-packages\thefuck\output_readers\__init__.py", line 20, in get_output
    return rerun.get_output(script, expanded)
  File "d:\python36\lib\site-packages\thefuck\output_readers\rerun.py", line 62, in get_output
    output = result.stdout.read().decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb2 in position 9: invalid start byte
@bahatiphill
Copy link

bahatiphill commented Oct 26, 2019

@nvbn would this be easier if we decode the output = result.stdout.read().decode('utf-8') using utf-32 instead of utf-8 ?

@Surya97
Copy link

Surya97 commented Oct 28, 2019

Hey, can I look into this issue?

@scorphus
Copy link
Collaborator

@Surya97, you are more than welcome! The Fuck really needs Windows users as contributors!

@KishinZW
Copy link
Author

Maybe we can using chardet to make it?

@anquegi
Copy link

anquegi commented Apr 14, 2020

I'm not sure to open a new issue since this is also open for ubuntu. I get the same proble wiht MAC OS X catalina. installed with homebrew and usd with a zsh plugin.

It generally worked well i.e.:

~ via ⬢ v12.4.0
➜ ls -j
ls: illegal option -- j
usage: ls [-@ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1%] [file ...]

~ via ⬢ v12.4.0
➜ fuck
ls -k [enter/↑/↓/ctrl+c]

but when I use a spanish character, for example in my keyboard ñ is near to l, so I cant type easily,
ls -ñ instead of ls -l (Really normaly not happens, but in this case I was thinking for an option than doesnt have ls)

so I tried with this:

~ via ⬢ v12.4.0 took 8s
➜ ls -ñ
ls: illegal option -- �
usage: ls [-@ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1%] [file ...]

~ via ⬢ v12.4.0
➜ fuck
Traceback (most recent call last):
  File "/usr/local/bin/thefuck", line 13, in <module>
    sys.exit(main())
  File "/usr/local/Cellar/thefuck/3.30/libexec/lib/python3.8/site-packages/thefuck/entrypoints/main.py", line 31, in main
    fix_command(known_args)
  File "/usr/local/Cellar/thefuck/3.30/libexec/lib/python3.8/site-packages/thefuck/entrypoints/fix_command.py", line 36, in fix_command
    command = types.Command.from_raw_script(raw_command)
  File "/usr/local/Cellar/thefuck/3.30/libexec/lib/python3.8/site-packages/thefuck/types.py", line 82, in from_raw_script
    output = get_output(script, expanded)
  File "/usr/local/Cellar/thefuck/3.30/libexec/lib/python3.8/site-packages/thefuck/output_readers/__init__.py", line 20, in get_output
    return rerun.get_output(script, expanded)
  File "/usr/local/Cellar/thefuck/3.30/libexec/lib/python3.8/site-packages/thefuck/output_readers/rerun.py", line 63, in get_output
    output = result.stdout.read().decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 22: invalid continuation byte

~ via ⬢ v12.4.0
➜ locale
LANG="es_ES.UTF-8"
LC_COLLATE="es_ES.UTF-8"
LC_CTYPE="es_ES.UTF-8"
LC_MESSAGES="es_ES.UTF-8"
LC_MONETARY="es_ES.UTF-8"
LC_NUMERIC="es_ES.UTF-8"
LC_TIME="es_ES.UTF-8"
LC_ALL=

to be fear I think that I have my locale well configured, but also ls doesn't catch ñ, but in environment varianles it works, it seems that ls only handles ascii internally?.

Thanks for this nice library for console use.

@scorphus
Copy link
Collaborator

This is the output Python gets:

b'ls: illegal option -- \xc3\nusage: ls [-@ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1%] [file ...]\n'

And indeed, \n is not a valid continuation for \xc3. That's very odd. 🤔

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

Successfully merging a pull request may close this issue.

5 participants