Skip to content

Commit

Permalink
avoid GHC head warning with explicit pattern matching + custom error
Browse files Browse the repository at this point in the history
  • Loading branch information
byorgey committed May 10, 2024
1 parent cb50606 commit 6d6bea7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/swarm-tournament/Swarm/Web/Tournament/Database/Query.hs
Original file line number Diff line number Diff line change
@@ -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" #-}

Expand Down Expand Up @@ -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;"
Expand Down

0 comments on commit 6d6bea7

Please sign in to comment.