Prevent failure when using fail! with invalid utf8.

Closes #16877.