module Data.TypeID.Error
(
TypeIDError(..)
) where
import Control.Exception
import Data.Text (Text)
data TypeIDError
=
TypeIDErrorPrefixTooLong Int
|
| TypeIDStartWithUnderscore
| TypeIDEndWithUnderscore
| TypeIDErrorPrefixInvalidChar Char
| TypeIDErrorPrefixMismatch Text Text
| TypeIDErrorUUIDError
deriving (TypeIDError -> TypeIDError -> Bool
(TypeIDError -> TypeIDError -> Bool)
-> (TypeIDError -> TypeIDError -> Bool) -> Eq TypeIDError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TypeIDError -> TypeIDError -> Bool
== :: TypeIDError -> TypeIDError -> Bool
$c/= :: TypeIDError -> TypeIDError -> Bool
/= :: TypeIDError -> TypeIDError -> Bool
Eq, Eq TypeIDError
Eq TypeIDError
-> (TypeIDError -> TypeIDError -> Ordering)
-> (TypeIDError -> TypeIDError -> Bool)
-> (TypeIDError -> TypeIDError -> Bool)
-> (TypeIDError -> TypeIDError -> Bool)
-> (TypeIDError -> TypeIDError -> Bool)
-> (TypeIDError -> TypeIDError -> TypeIDError)
-> (TypeIDError -> TypeIDError -> TypeIDError)
-> Ord TypeIDError
TypeIDError -> TypeIDError -> Bool
TypeIDError -> TypeIDError -> Ordering
TypeIDError -> TypeIDError -> TypeIDError
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: TypeIDError -> TypeIDError -> Ordering
compare :: TypeIDError -> TypeIDError -> Ordering
$c< :: TypeIDError -> TypeIDError -> Bool
< :: TypeIDError -> TypeIDError -> Bool
$c<= :: TypeIDError -> TypeIDError -> Bool
<= :: TypeIDError -> TypeIDError -> Bool
$c> :: TypeIDError -> TypeIDError -> Bool
> :: TypeIDError -> TypeIDError -> Bool
$c>= :: TypeIDError -> TypeIDError -> Bool
>= :: TypeIDError -> TypeIDError -> Bool
$cmax :: TypeIDError -> TypeIDError -> TypeIDError
max :: TypeIDError -> TypeIDError -> TypeIDError
$cmin :: TypeIDError -> TypeIDError -> TypeIDError
min :: TypeIDError -> TypeIDError -> TypeIDError
Ord)
instance Show TypeIDError where
show :: TypeIDError -> String
show :: TypeIDError -> String
show (TypeIDErrorPrefixTooLong Int
n)
= [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [String
"Prefix with ", Int -> String
forall a. Show a => a -> String
show Int
n, String
" characters is too long!"]
show TypeIDError
TypeIDExtraSeparator
= String
"The underscore separator should not be present if the prefix is empty!"
show TypeIDError
TypeIDStartWithUnderscore
= String
"The prefix should not start with an underscore!"
show TypeIDError
TypeIDEndWithUnderscore
= String
"The prefix should not end with an underscore!"
show (TypeIDErrorPrefixInvalidChar Char
c)
= [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [String
"Prefix contains invalid character ", Char -> String
forall a. Show a => a -> String
show Char
c, String
"!"]
show (TypeIDErrorPrefixMismatch Text
expPrefix Text
actPrefix)
= [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [ String
"Expected prefix ", Text -> String
forall a. Show a => a -> String
show Text
expPrefix, String
" but got "
, Text -> String
forall a. Show a => a -> String
show Text
actPrefix, String
"!" ]
show TypeIDError
TypeIDErrorUUIDError
= String
"Invalid UUID part!"
{-# INLINE show #-}
instance Exception TypeIDError