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

Prevent crashing from UnicodeDecodeError #988

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

Conversation

jmoldow
Copy link

@jmoldow jmoldow commented Mar 23, 2016

On Python 2, sys.stdout and print can normally handle any combination of str and unicode objects. However, StringIO.StringIO can only safely handle one or the other. If the program writes both a unicode string, and a non-ASCII str string, then the getvalue() method will fail with UnicodeDecodeError [1].

In nose, that causes the script to suddenly abort, with the cryptic UnicodeDecodeError.

This fix catches UnicodeError when trying to get the captured output, and will replace the captured output with a warning message.

Fixes #816

[1] https://github.com/python/cpython/blob/2.7/Lib/StringIO.py#L258

On Python 2, `sys.stdout` and `print` can normally handle any
combination of `str` and `unicode` objects. However,
`StringIO.StringIO` can only safely handle one or the other. If
the program writes both a `unicode` string, and a non-ASCII
`str` string, then the `getvalue()` method will fail with
`UnicodeDecodeError` [1].

In nose, that causes the script to suddenly abort, with the
cryptic `UnicodeDecodeError`.

This fix catches `UnicodeError` when trying to get the captured
output, and will replace the captured output with a warning
message.

Fixes nose-devs#816

[1] <https://github.com/python/cpython/blob/2.7/Lib/StringIO.py#L258>
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.

UnicodeDecodeError with 1.3.1 and python2.7
1 participant