more appropriate errors in edge cases involving invalid encoding sequences