Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Better error message for all nulls in sum type

  • Loading branch information...
commit be187f37a89b1d8ba0613b80532d8912aa9151e2 1 parent 4523390
@snoyberg snoyberg authored
View
9 persistent-template/Database/Persist/TH.hs
@@ -377,6 +377,10 @@ mkHalfDefined constr count' =
$ foldl AppE (ConE constr)
(replicate count' $ VarE $ mkName "undefined")) []]
+isNotNull :: PersistValue -> Bool
+isNotNull PersistNull = False
+isNotNull _ = True
+
mkFromPersistValues :: EntityDef -> Q [Clause]
mkFromPersistValues t@(EntityDef { entitySum = False }) = do
nothing <- [|Left $(liftT "Invalid fromPersistValues input")|]
@@ -395,7 +399,7 @@ mkFromPersistValues t@(EntityDef { entitySum = False }) = do
where
go ap' x y = InfixE (Just x) ap' (Just y)
mkFromPersistValues t@(EntityDef { entitySum = True }) = do
- nothing <- [|Left $(liftT "Invalid fromPersistValues input")|]
+ nothing <- [|Left $(liftT "Invalid fromPersistValues input: sum type with all nulls")|]
clauses <- mkClauses [] $ entityFields t
return $ clauses `mappend` [Clause [WildP] (NormalB nothing) []]
where
@@ -411,7 +415,8 @@ mkFromPersistValues t@(EntityDef { entitySum = True }) = do
constr = ConE $ sumConstrName t field
fmap' <- [|fmap|]
fs <- [|fromPersistValue $(return $ VarE x)|]
- let clause = Clause [pat] (NormalB $ InfixE (Just constr) fmap' (Just fs)) []
+ let guard' = NormalG $ VarE 'isNotNull `AppE` VarE x
+ let clause = Clause [pat] (GuardedB [(guard', InfixE (Just constr) fmap' (Just fs))]) []
clauses <- mkClauses (field : before) after
return $ clause : clauses
View
2  persistent-template/persistent-template.cabal
@@ -1,5 +1,5 @@
name: persistent-template
-version: 1.1.2.2
+version: 1.1.2.3
license: MIT
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>

0 comments on commit be187f3

Please sign in to comment.
Something went wrong with that request. Please try again.