kovidgoyal / kitty

Cross-platform, fast, feature-rich, GPU based terminal
https://sw.kovidgoyal.net/kitty/
GNU General Public License v3.0
24.15k stars 972 forks source link

Unicaud error on +kitten icat #924

Closed sirex closed 6 years ago

sirex commented 6 years ago

I got this error:

> kitty +kitten icat Ekrano\ nuotrauka\ iš\ 2018-07-14\ 17-20-23.png 
Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/bin/../lib/kitty/__main__.py", line 110, in <module>
    main()
  File "/usr/bin/../lib/kitty/__main__.py", line 101, in main
    namespaced(['+', first_arg[1:]] + sys.argv[2:])
  File "/usr/bin/../lib/kitty/__main__.py", line 61, in namespaced
    func(args[1:])
  File "/usr/bin/../lib/kitty/__main__.py", line 56, in run_kitten
    run_kitten(kitten)
  File "/usr/bin/../lib/kitty/kittens/runner.py", line 95, in run_kitten
    runpy.run_module('kittens.{}.main'.format(kitten), run_name=run_name)
  File "/usr/lib/python3.7/runpy.py", line 208, in run_module
    return _run_code(code, {}, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/bin/../lib/kitty/kittens/icat/main.py", line 327, in <module>
    main()
  File "/usr/bin/../lib/kitty/kittens/icat/main.py", line 310, in main
    process(item, args)
  File "/usr/bin/../lib/kitty/kittens/icat/main.py", line 193, in process
    show(outfile, width, height, fmt, transmit_mode, align=args.align, place=args.place)
  File "/usr/bin/../lib/kitty/kittens/icat/main.py", line 166, in show
    write_gr_cmd(cmd, standard_b64encode(os.path.abspath(outfile).encode(fsenc)))
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 44-45: surrogates not allowed

Versions:

> pacman -Q python kitty
python 3.7.0-3
kitty 0.12.0-1

Not sure, maybe error because of file name, that contains an unicode letter?

kovidgoyal commented 6 years ago

Works for me with that filename on Arch. And that error is indicating an error with temporary filename/path not input filename. Make sure your TEMP env var is set to /tmp or similar. Or use --transfer-mode=stream to avoid temp files.

sirex commented 6 years ago

Ok, after digging a bit deeper I found, that issue is with š character, python receives it as \udcc5\udca1. And because of that unicode error is raised:

> python -c "print('\udcc5\udca1')"                                    
Traceback (most recent call last):
  File "<string>", line 1, in <module>
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 0-1: surrogates not allowed

I have no idea, how that happens, but it work with pure python:

> python -c "import sys; print(repr(sys.argv[1]))" š                
'š'

But if I do that with kitty, by modifying /usr/lib/kitty/__main__.py and adding print(repr(sys.argv[1])) to the top of main function, I get this:

> kitty š    
'\udcc5\udca1'

So I guess, argument gets corrupted earlier before Python.

I did tried calling kitty with TEMP=/tmp, but that does not work too. --transfer-mode=stream does work.

kovidgoyal commented 6 years ago

Make sure you have your locale setup for UTF-8 correctly. LANG should be something like

LANG=en_US.UTF-8

kitty, unlike python assumes utf-8 everywhere.

sirex commented 6 years ago

Nope:

> LANG=lt_LT.UTF-8 kitty š
'\udcc5\udca1'
> LANG=en_US.UTF-8 kitty š
'\udcc5\udca1'
kovidgoyal commented 6 years ago

Then I have no idea, sorry. Works fine for me:

kitty +runpy 'import sys; print(repr(sys.argv[-1]))' š                                                                                      
'š'
kovidgoyal commented 6 years ago

Try building kitty from source so it uses your system python, that might fix it.

sirex commented 6 years ago
> kitty +runpy 'import sys; print(repr(sys.argv[-1]))' š
'+runpy'
'\udcc5\udca1'