Toolchain problems driving me batty (stack? ghc?)


#1

I’ve been peacefully and happily working in Haskell for a year or so. I develop on an up-to-date Ubuntu system; my editor is emacs. At some point in the last couple weeks I started having problems that I’ve been unable to resolve, and I’m hoping someone can point me in the right direction.

Unfortunately by the time I noticed what was going on, I had already lost track of what changed from the working setup to now, but at the moment I believe that all of the relevant tools are installed either via nix-env or stack. The compiler is ghc 8.6.5.

The symptoms are somewhat varied, but boil down to the following message coming from invocation of “stack build”:

<stderr>: commitAndReleaseBuffer: invalid argument (invalid character)

According to the internet, this symptom seems to be related, at least sometimes, to the lack of proper Unicode encoding settings in the terminal invoking the build; my shell has LC_ALL set to en_US.UTF-8 though, so it’s probably something else (or at least a more subtle variant).

One version of the symptom occurs during intermediate stages of the build, seemingly at random. The build will stop at some point, with the above message, while building libraries from hackage. If I resume the build with an identical invocation of “stack build” then it will continue, working from where it left off. The computer does not seem to be running out of memory while this is happening, and there is plenty of swap and disk. The network connection seems to be stable too.

If I keep repeating “stack build,” eventually the build will complete. However, if I have inserted an error in one of my own source files (something like “x = y” at the end of my Main.hs, where “y” is not defined) then the error emitted at the end is also the above “commitAndReleaseBuffer” message, instead of the expected complaint that y is not in scope.

Except sometimes, after erasing .stack-work, and rebuilding with “stack build --silent”, I’ll see an actual error at the end. I’ve been flailing around so much on this that I’m really not certain, but there does seem to be something nondeterministic here.

Anyway, kind of at the end of my rope here and would appreciate some insight.


#2

Are you perhaps using some more exotic modes of compilation like Nix or Docker? Either in stack.yaml or your global configuration.

I recall solving this problem temporarily by adding --color never to my commands, disabling POSIX colors etc., and later upgrading to a newer stack executable which fixed these problems - does stack upgrade do anything for you? Alternatively, if --color never helps, that narrows down your problem…


#3

Nothing exotic, this is a very basic build right now, though it does have a long list of dependencies.

Sadly, I tried specifying --color=never with no change, likewise running from a terminal with colors disabled. I was already running stack 2.1.3.1, which stack upgrade tells me is the latest version.

I do appreciate the suggestions though!


#4

In that case, I’d say you’re better off opening an issue in the commercialhaskell/stack repo, where there’ll be more (and more knowledgeable) eyes on your problem. The closest issue to yours is https://github.com/commercialhaskell/stack/issues/4943, but that one is for Windows and not Stack-from-Nix-on-Ubuntu.


#5

Thanks for the pointer – I think it’s probably the same issue; I’ll watch it.

One thing that I’m sure you appreciate but I’ll make explicit for the sake of potential others reading: without a build system that produces useful error messages, developing in Haskell gets a lot harder. For me right now, pretty much impossible.


#6

Looking around a bit more after receiving your reply, I found https://github.com/input-output-hk/haskell.nix/issues/229 where the same problem with GHC 8.6.5 on Nix has been solved by setting not only LC_ALL to x.UTF-8 but also LANG, to the same value. Does that help you?


#7

I had already tried that some time ago, but hadn’t thought it had worked…

However, this time, it did! Not sure what else has changed, but omg thank you!