[Haskell-cafe] Yesod double free or corruption

Manuel Gómez targen at gmail.com
Wed Dec 12 23:53:13 CET 2012


On Wed, Dec 12, 2012 at 12:24 PM, Andras Gyomrey <lgandras at gmail.com> wrote:
> Hi,
>
> i got the following error using "yesod devel" it happened after adding the
> file which seems to have invalid content (not true). What should i do?

The first bit of your error message indeed indicates
`./Handler/Model/Season.hs` isn’t encoded as `hGetContents` expects:

> yesod: ./Handler/Model/Season.hs: hGetContents: invalid argument (invalid byte sequence)

`System.IO.hGetContents` converts into Unicode from the default
encoding configured in your system unless explicitly told otherwise
with `hSetEncoding`[1].  You can check what this encoding is with the
GHC primitive `GHC.IO.Encoding.getLocaleEncoding`[2], or with the
somewhat less reliable `System.IO.localeEncoding` runtime constant.

This StackOverflow answer has some good pointers on inference and
validation of file encoding: <http://unix.stackexchange.com/a/11648>

The simplest solution is, of course, to set your system encoding to
UTF‐8, and make sure your source code is encoded accordingly.  GNU
iconv is quite handy for encoding conversions.  Remember to tell your
editor to default to UTF‐8 in case it doesn’t detect the system
encoding — or better yet, switch to a better editor that does.

The heap corruption does indeed indicate a bug somewhere, though not
necessarily in Yesod code.  If I understand this correctly, the
exception is uncaught (and printed by the default uncaught exception
handler[4] that, in turn, calls `errorBelch` in the RTS[5]) and the
heap corruption becomes evident only later during the GHC runtime’s
cleanup, whatever that may be.

[1]: <http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#g:23>
[2]: <http://www.haskell.org/ghc/docs/latest/html/libraries/base/GHC-IO-Encoding.html#v:getLocaleEncoding>
[3]: <http://www.gnu.org/savannah-checkouts/gnu/libiconv/documentation/libiconv-1.13/iconv.1.html>
[4]: <http://hackage.haskell.org/packages/archive/base/4.2.0.0/doc/html/src/GHC-Conc.html#uncaughtExceptionHandler>
[5]: Lines 34 and 174–202 of <rts/RTSMessages.c> in the GHC source
<http://darcs.haskell.org/ghc.git/rts/RtsMessages.c>



More information about the Haskell-Cafe mailing list