module Sos.Exception
( SosException(..)
) where
import Sos.Utils
import Control.Exception (Exception)
import Data.ByteString (ByteString)
import Data.Typeable (Typeable)
data SosException
= SosRegexException
ByteString
String
| SosCommandParseException
ByteString
| SosCommandApplyException
[Either Int ByteString]
[ByteString]
String
deriving (Eq, Typeable)
instance Show SosException where
show (SosRegexException pattrn err) =
"Error compiling regex '" ++ unpackBS pattrn ++ "': " ++ err
show (SosCommandParseException template) =
"Error parsing command '" ++ unpackBS template ++ "'"
show (SosCommandApplyException template vars err) =
"Error applying template '" ++ reconstruct template ++ "' to " ++ show vars ++ ": " ++ err
where
reconstruct :: [Either Int ByteString] -> String
reconstruct = concatMap
(\case
Left n -> '\\' : show n
Right bs -> unpackBS bs)
instance Exception SosException