escape invalid characters in error messages