From 8ddba96628a5f1d32d99d6b1b5f89e9e87e5df14 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Fri, 17 Mar 2023 15:41:46 +1300 Subject: [PATCH] Silence erroneous exceptions. --- Graphics/Text/Font/Choose/Result.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Graphics/Text/Font/Choose/Result.hs b/Graphics/Text/Font/Choose/Result.hs index c66e78a..57bd8bc 100644 --- a/Graphics/Text/Font/Choose/Result.hs +++ b/Graphics/Text/Font/Choose/Result.hs @@ -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 -- 2.30.2