Uncaught exception when UTF8 characters written to terminal that doesn't support UTF8
USE CASE: WHAT DO YOU WANT TO DO?
Run barcode splitter on barcodes containing utf8 characters that outputs standard out to the terminal.
STEPS TO REPRODUCE AN ISSUE (OR TRIGGER A NEW FEATURE)
- Manually run test3 without redirecting stdout in a terminal that does not support utf8 encoding
CURRENT BEHAVIOR
The UTF8 characters in one of the barcode sample IDs causes an exception when it tries to write the stats table to stdout:
Traceback (most recent call last):
File "../barcode_splitter.py", line 1030, in <module>
sys.exit(main())
File "../barcode_splitter.py", line 310, in main
suffix=options.suffix)
File "../barcode_splitter.py", line 670, in printCounts
sys.stdout.write(line)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 2-3: ordinal not in range(128)
EXPECTED BEHAVIOR
Catch the exception and print an error suggesting the likely cause (terminal does not support UTF8 characters that were found in the sample IDs).
DEVELOPERS ONLY SECTION
SUGGESTED CHANGE (Pseudocode optional)
try, catch, print error.
LEVEL OF EFFORT - developers only
trivial
COMMENTS
Comments (4)
-
reporter -
reporter @lance_parsons - Is there any way to detect the encoding so the user doesn't have to know to supply the environment variable?
-
reporter - changed status to open
Starting work
-
reporter - changed status to resolved
Resolved in pull request #19.
- Log in to comment
I was looking into this and have confirmed that the issue was that I'd neglected to put "PYTHONIOENCODING='UTF-8'" in front of the command when I ran test 3 manually. If I include that, it runs fine. This didn't have anything to do with the terminal support for UTF8.