Have you ran into this while installing QuickCheck on FreeBSD?

QuickCheck-2.7.5 depends on tf-random-0.5 which failed to install.
tf-random-0.5 failed during the final install step. The exception was:
/tmp/pkgConf-tf-random-043046.5: hGetContents: invalid argument (invalid byte
sequence)

I wasted a lot of time trying to debug this, but today I was fighting with a similar problem with Jekyll and finally found an answer. In short, the issue is that tf-random (as well as Liquid) needs UTF-8 input. And FreeBSD does not use that encoding by default.

The solution

Add appropriate language and encoding tag. to the default: section of your /etc/login.conf

If you your language is en_US then you lang tag would be :lang=en_US.UTF-8:

Before:

default:\
  :passwd_format=md5:\

  *many lines...*

  :umask=022:

After:

default:\
  :passwd_format=md5:\

  *many lines...*

  :umask=022:\
  :lang=en_US.UTF-8:

To reload the changes, run (as root):

cap_mkdb /etc/login.conf

After that relogin to your environment. More details in the mentioned post. Thanks to Patrick Gibson for sharing the solution.