module Client.EventLoop.Errors
( exceptionToLines
) where
import Control.Exception
import Data.List.NonEmpty (NonEmpty(..))
import OpenSSL.Session
import Hookup (ConnectionFailure(..))
exceptionToLines ::
SomeException ->
NonEmpty String
exceptionToLines
= indentMessages
. exceptionToLines'
indentMessages :: NonEmpty String -> NonEmpty String
indentMessages (x :| xs) = x :| map ("⋯ "++) xs
exceptionToLines' ::
SomeException ->
NonEmpty String
exceptionToLines' ex
| Just err <- fromException ex = explainHookupError err
| Just _ <- fromException ex :: Maybe ConnectionAbruptlyTerminated =
"Connection abruptly terminated" :| []
| Just (ProtocolError e) <- fromException ex =
("TLS protocol error: " ++ e) :| []
| Just ioe <- fromException ex =
explainIOError ioe :| []
| otherwise = displayException ex :| []
explainIOError :: IOError -> String
explainIOError ioe = "IO error: " ++ displayException ioe
explainHookupError :: ConnectionFailure -> NonEmpty String
explainHookupError e =
case e of
ConnectionFailure exs ->
"Connect failed" :| map explainIOError exs
LineTooLong ->
"IRC message too long" :| []
LineTruncated ->
"IRC message incomplete" :| []
_ -> displayException e :| []