module Sos.Exception
( SosException(..)
) where
import Sos.Utils
import Data.ByteString (ByteString)
data SosException
= SosRegexException
ByteString
String
| SosCommandParseException
ByteString
| SosCommandApplyException
[Either Int ByteString]
[ByteString]
String
deriving Eq
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)