Skip to content

Commit 6f5d6fa

Browse files
committed
Merge pull request #22 from commercialhaskell/exceptT-Text-IO
ExceptT Text IO
2 parents 8fcf914 + 0ee6532 commit 6f5d6fa

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

content/exceptions-best-practices.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ transformer stack used in a public-facing API. It's usually better to express a
5555
function in terms of typeclass requirements, using mtl typeclasses as
5656
necessary.
5757

58+
A similar pattern is
59+
60+
```haskell
61+
myFunction :: String -> ExceptT Text IO Int
62+
```
63+
64+
This is usually done with the idea that in the future the error type will be changed from `Text` to something like `MyException`. However, `Text` may end up sticking around forever because it helps avoid the composition problems of a real data type. However that leads to expressing useful error data types as unstructured `Text`.
65+
66+
Generally the solution to the `ExceptT IO` anti-pattern is to return an `Either` from more functions and throw an exception for uncommon errors. Note that returning `Either` from `ExceptT IO` means there are now 3 distinct sources of errors in just one function.
67+
68+
Please not that using ExceptT, etc with a non-IO base monad (for example with pure code) is a perfectly fine pattern.
69+
70+
5871
### Mask-them-all anti-pattern
5972

6073
This anti-pattern goes like this: remembering to deal with async exceptions everywhere is hard, so I'll just mask them all.

0 commit comments

Comments
 (0)