Better error message and test for invalid UTF-8 sequences.