[Haskell-cafe] How to handle recoverable errors in multi-step computation?
Lian Hung Hon
hon.lianhung at gmail.com
Sat Feb 6 02:58:18 UTC 2016
I have a multi-step computation. The steps are predefined, but users can
choose which steps to execute (something like a recipe). Here is an example
Step 1 - Get data from network (multiple HTTP calls) and put into a list
Step 2 - Process the data (e.g. average, sum, median, etc.)
Step 3 - Persist result to database
Sometimes, Step 1 can fail for some of the HTTP calls. When this happens,
Step 2 should continue as much as possible using whatever data that has
been retrieved, but somehow indicate that an error has occurred and the
result is partial.
Q1: What is the idiomatic way of achieving this? Using throwError in
Control.Monad.Except aborts the computation, which isn't what I want.
Q2: (General software design) Furthermore, where should the error be
logged? Logging it in both Step 1 and 2 preserves modularity for each of
the steps, unfortunately it would result in duplicate error messages. What
is the best practice for this?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe