From 66f989e691e56ab4d765437ff58db260010c652e Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Fri, 20 Nov 2020 22:39:39 +0100 Subject: [PATCH] Fix FromJSONKey instances This led to silent Nothing when the parser failed. --- lib/GHCup/Types/JSON.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/GHCup/Types/JSON.hs b/lib/GHCup/Types/JSON.hs index e68a608..5ca24b9 100644 --- a/lib/GHCup/Types/JSON.hs +++ b/lib/GHCup/Types/JSON.hs @@ -111,10 +111,10 @@ instance ToJSONKey (Maybe Versioning) where instance FromJSONKey (Maybe Versioning) where fromJSONKey = FromJSONKeyTextParser $ \t -> - if t == T.pack "unknown_versioning" then pure Nothing else pure $ just t + if t == T.pack "unknown_versioning" then pure Nothing else just t where just t = case versioning t of - Right x -> pure x + Right x -> pure $ Just x Left e -> fail $ "Failure in (Maybe Versioning) (FromJSONKey)" <> show e instance ToJSONKey Platform where @@ -157,10 +157,10 @@ instance ToJSONKey (Maybe Version) where instance FromJSONKey (Maybe Version) where fromJSONKey = FromJSONKeyTextParser $ \t -> - if t == T.pack "unknown_version" then pure Nothing else pure $ just t + if t == T.pack "unknown_version" then pure Nothing else just t where just t = case version t of - Right x -> pure x + Right x -> pure $ Just x Left e -> fail $ "Failure in (Maybe Version) (FromJSONKey)" <> show e instance ToJSON Version where