Solving Haskell ‘commitAndReleaseBuffer: invalid argument (invalid character)’

Problem:

When running your Haskell program, you get the following error:

commitAndReleaseBuffer: invalid argument (invalid character)7

Solution

Although it is not clear yet what causes this issue, changing the LANG environment variable solves the problem. In our case, with a value of LANG=en_US.UTF-8 or LANG=C the issue appeared reproducibly when writing certain UTF-8 data to a file.

When using

export LANG=en_GB.UTF-8

the issue didn’t appear again. In some cases, it might be required to use other values for LANG.