You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The shErrorReturnCode exception class sets the exception message to a Unicode string, regardless of Python version. That's not really an option in Python 2, but it just happens to work when your Unicode string is ASCII safe.
However, when the process exited with non-ASCII characters on stderr or stdout, then showing the exception in a traceback results in a <exception str() failed> exception message, because the str() call on the exception instance fails.
Demo reproducing the problem, run with Python 2.7:
In Python3, the str type is a text string. On Python2, the str type is
a byte string. When we raise exceptions we should use native strings
otherwise Python may end up truncating or omitting the exception
message (on Python2) or mangling them (if a byte string were to be given
on Python3).
Fixesamoffat#463
The
sh
ErrorReturnCode
exception class sets the exception message to a Unicode string, regardless of Python version. That's not really an option in Python 2, but it just happens to work when your Unicode string is ASCII safe.However, when the process exited with non-ASCII characters on stderr or stdout, then showing the exception in a traceback results in a
<exception str() failed>
exception message, because thestr()
call on the exception instance fails.Demo reproducing the problem, run with Python 2.7:
This outputs
When you catch the exception, the
.args[0]
attribute shows why:So on Python 2, please encode the message to a suitable
str
object before setting it.The text was updated successfully, but these errors were encountered: