How to Debug Haskell in Production

This is a blog about the development of Yeller, The Exception Tracker with Answers

Read more about Yeller here

For years, folk have been saying the same things about wanting to use Haskell in production:

I’d love to use Haskell in Production, but

Then they reel off a bunch of issues, many of which are much better than they used to be (many more people understand the basic principles behind Haskell, as more and more up and coming languages adopt them). But there’s one thing that always stuck out to me:

I’d love to use Haskell in Production, but

How am I meant to debug errors without stacktraces?

Here’s what most Haskell programmers see when there’s an error (even in production):

*** Exception: Prelude.head: empty list

That’s it. No stacktrace, no idea who called head with an empty list, nothing.

Stacktraces are everywhere in other programmming langues. Many developers spend most of their days staring at them. They’re an extremely useful tool to diagnose issues whilst developing. But where they really come into play is when you have an error in production. Knowing exactly which part of your app broke, or which library that you depend on did something unsafe is best done via a stacktrace.

Whilst Haskell code is often more robust than many other languages, folk still throw exceptions from time to time. Libraries you depend on might call some unsafe function from the Prelude that you don’t know about, etc. For these cases, you need a stacktrace, especially if the error happens in production.

Lazy Evaluation: a mixed blessing

Lazy Evaluation is the problem behind stacktraces being difficult in Haskell. In lazy languages, there is no stack, which makes getting a stacktrace much weirder than it is in strict languages. You can’t just walk up it - it doesn’t exist!

Haskell is different

Just getting stacktraces out of exceptions ain’t the whole game. Haskell folk also often use values to represent errors, via Either, EitherT and so on. In these cases, you’d like to get a stacktrace without carrying around a load of information yourself.

Haskell Stacktraces: A Solved Problem

Due to recent work on GHC though (as of 7.10), all these issues are now handled by the compiler. If you compile your app with profiling mode (which doesn’t impact production performance very much), you can get stacktraces out of GHC, via GHC.Stack.

Tracking Production Haskell errors with Yeller

As of today, Yeller now supports tracking errors in Haskell. Yeller’s an error tracker, with much more powerful debugging tools than the typical “tracker”. It’ll let you dig into the nastiest, weirdest production error and fix it, without resorting to putStrLn debugging in production. Read more about Yeller here.

Sign up for your free 30 day trial today

Exceptions got you frustrated? Sign up to Yeller to automatically track them, and then fix them with your new diagnosis superpowers.

Yeller works with Clojure, Ruby, Rails, Java, JavaScript, Go, Haskell and Node.js