Closed bogdanm closed 8 years ago
@autopulated
I don't think this is the right fix – in any case it is only changing the behaviour for yotta search
, but many other commands could have unicode output.
I'd be tempted just to document that you should set PYTHONIOENCODING
to an appropriate value if you're piping into a file, or to catch this error globally, and exit with a more useful error message.
FWIW in python 3 this is fixed (the default encoding is UTF-8), we could also just hack things (with setdefaultencoding) so the default encoding is UTF-8 under python 2 also, but this can break things in really quite subtle ways (see the Let's break dictionaries! section here: https://anonbadger.wordpress.com/2015/06/16/why-sys-setdefaultencoding-will-break-code/).
I'd be tempted just to document that you should set PYTHONIOENCODING to an appropriate value if you're piping into a file, or to catch this error globally, and exit with a more useful error message.
Yes, this looks like a much better idea. I'd add this information to the yotta documentation.
While #727 is not technically yotta's fault, it can be quite an annoying issue for anything that tries to redirect yotta's output. This patch attempts a simple fix for that by performing a dumb Unicode to ASCII translation everytime an UnicodeEncodeError is raised.