I use the error function to communicate a massive programmer mistake (kind of like a c assert), where I want the program to immediately fail and force me to fix an obvious bug (as opposed to standard runtime exceptions). This has worked well for years, but I'm currently working on a multi-threaded program, where it is now failing me.
Calling error in a thread doesn't exit the program. This is well documented, https://hackage.haskell.org/package/base-4.8.2.0/docs/Control-Concurrent.html. This problem also exists for System.Exit.die, Control.Exception.Base.assert, etc.
I've seen examples that get around this program by building a heavyweight communication method between sub-threads and the main one, but this is rarely practical for my purposes, for many reasons:
- My threads are often created by libraries, like conduits mergeSources.
erroris often thrown in library calls, like when you callhead [].- If I need to route through inter-thread communication, it will make it too easy to miss that mechanism.
Is there a way to force the whole program to deliberately crash from a thread?