~alcinnz/fontconfig-pure

8ddba96628a5f1d32d99d6b1b5f89e9e87e5df14 — Adrian Cochrane 1 year, 2 months ago 856c312 master
Silence erroneous exceptions.
1 files changed, 6 insertions(+), 2 deletions(-)

M Graphics/Text/Font/Choose/Result.hs
M Graphics/Text/Font/Choose/Result.hs => Graphics/Text/Font/Choose/Result.hs +6 -2
@@ 6,10 6,14 @@ import Foreign.Ptr (Ptr, nullPtr)
import Control.Exception (throwIO, throw, Exception)

data Result = Match | NoMatch | TypeMismatch | ResultNoId | OutOfMemory | Other
    deriving (Eq, Show, Read, Enum)
    deriving (Eq, Show, Read, Enum, Bounded)

resultFromPointer :: Ptr Int -> IO Result
resultFromPointer res = toEnum <$> peek res
resultFromPointer res = do
    ret <- peek res
    if ret > fromEnum (maxBound :: Result) || ret < fromEnum (minBound :: Result)
    then return Match -- Probably an erroneous value. FIXME Understand why this happens.
    else return $ toEnum ret

data Error = ErrTypeMismatch | ErrResultNoId | ErrOutOfMemory deriving (Eq, Show, Read)
instance Exception Error