xonsh / xonsh

:shell: Python-powered shell. Full-featured and cross-platform.
http://xon.sh
Other
8.43k stars 641 forks source link

Unicode on $PROMPT? generate exceptions #1499

Closed santagada closed 8 years ago

santagada commented 8 years ago

On xterm inside xquartz (os x X11 server):

Traceback (most recent call last):
  File "/Users/santagada/devel/xonsh/xonsh/proc.py", line 349, in wrapped_simple_command
    r = f(args, i)
  File "/Users/santagada/devel/xonsh/xonsh/aliases.py", line 257, in source_alias
    builtins.execx(fp.read(), 'exec', builtins.__xonsh_ctx__)
  File "/usr/local/Cellar/python3/3.5.2/Frameworks/Python.framework/Versions/3.5/lib/python3.5/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 397: ordinal not in range(128)

I think it is on running my $PROMPT function, but maybe it is an app I run on login (archey)

scopatz commented 8 years ago

What did you run right before this? And how did you start xonsh?

AstraLuma commented 8 years ago

What's your LOCALE/LANG/LC_* variables? Are you using unicode in your source or \u/\U/\N escapes?

Is this fixed by #1471?

scopatz commented 8 years ago

I agree with @astronouth7303 that this seems like it is related to the other issue.

santagada commented 8 years ago

using master from right now and xon.sh I still see:

xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
Traceback (most recent call last):
  File "/Users/santagada/devel/xonsh/xonsh/proc.py", line 349, in wrapped_simple_command
    r = f(args, i)
  File "/Users/santagada/devel/xonsh/xonsh/aliases.py", line 257, in source_alias
    builtins.execx(fp.read(), 'exec', builtins.__xonsh_ctx__)
  File "/usr/local/Cellar/python3/3.5.2/Frameworks/Python.framework/Versions/3.5/lib/python3.5/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 397: ordinal not in range(128)
santagada@appletart ~ $ 

but if I start xonsh right after it it both doesn't print an exception and has my prompt (and not xonsh default one as the message up)

I tried changing xon.sh to my LANG/LC_ALL values:

#!/bin/sh

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

# run python
/usr/bin/env PYTHONUNBUFFERED=1 /usr/local/bin/python3 -u -m xonsh $@

but it didn't help.

If I try to load my prompt function on the first Xonsh it always gives the same error and switches it back to default:

$ source prompt.xsh 
xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
Traceback (most recent call last):
  File "/Users/santagada/devel/xonsh/xonsh/proc.py", line 349, in wrapped_simple_command
    r = f(args, i)
  File "/Users/santagada/devel/xonsh/xonsh/aliases.py", line 257, in source_alias
    builtins.execx(fp.read(), 'exec', builtins.__xonsh_ctx__)
  File "/usr/local/Cellar/python3/3.5.2/Frameworks/Python.framework/Versions/3.5/lib/python3.5/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 397: ordinal not in range(128)
scopatz commented 8 years ago

This is probably because the source alias is not passing in $XONSH_ENCODING and errors into the open() call https://github.com/xonsh/xonsh/blob/master/xonsh/aliases.py#L256

santagada commented 8 years ago

Yes I have unicode literals in that file. Is it easy for you to fix?

scopatz commented 8 years ago

Ahh yes, this is easy for me to fix.

scopatz commented 8 years ago

See #1519