From 6d6bea759fc799e5536dc5ecd24a55f8e2f95246 Mon Sep 17 00:00:00 2001 From: Brent Yorgey Date: Fri, 10 May 2024 14:13:45 -0500 Subject: [PATCH] avoid GHC `head` warning with explicit pattern matching + custom error --- .../Swarm/Web/Tournament/Database/Query.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/swarm-tournament/Swarm/Web/Tournament/Database/Query.hs b/src/swarm-tournament/Swarm/Web/Tournament/Database/Query.hs index 70f5eb8a9..cbbb7a871 100644 --- a/src/swarm-tournament/Swarm/Web/Tournament/Database/Query.hs +++ b/src/swarm-tournament/Swarm/Web/Tournament/Database/Query.hs @@ -1,7 +1,6 @@ {-# LANGUAGE OverloadedStrings #-} {-# OPTIONS_GHC -fno-warn-orphans #-} {-# OPTIONS_GHC -fno-warn-unrecognised-pragmas #-} -{-# OPTIONS_GHC -fno-warn-x-partial #-} {-# HLINT ignore "Functor law" #-} @@ -211,8 +210,12 @@ getUserId conn userAlias = do <$> query conn "SELECT id FROM users WHERE alias = ?;" (Only userAlias) maybe insertNew return maybeId where + -- Avoid GHC warning re: partiality of head + queryHead = \case + [] -> error "Query result in getUserId should never be empty!" + hd : _ -> hd insertNew = - fmap (UserId . fromOnly . head) + fmap (UserId . fromOnly . queryHead) $ query conn "INSERT INTO users (alias) VALUES (?) RETURNING id;"